The spots say Northam is "weak on MS-13" as images of tattooed Latino men and the gang motto "Kill, Rape, Control" pop up on the screen.
Independent fact-checkers deemed the ads misleading.
"We have seen this so many times before," said Obama, who spent five minutes tearing into the strategy. "You've got the advertisement. There is some ominous voice. Everything is kind of dark. Just letting you know that somebody is coming to get you. That our values are at risk if you vote for Ralph. They don't really tell you exactly why. We have seen it before. And it is a tactic that shows Ralph's opponent does not think highly of Virginians."
Northam, a former Army doctor and pediatric neurologist, is in a neck-and-neck race with Gillespie, a former lobbyist and GOP strategist.
"I don't think that someone who spent his life performing surgery on soldiers and children is suddenly cozying up to street gangs," Obama said to laughter from the crowd of 7,500 at the city's convention center. "That strains credulity. That sounds like a fib. Sounds like an okey-doke. Nobody believes that."
He suggested that Gillespie's ads were hypocritical, noting that as a former chairman of the Republican National Committee and a party strategist, Gillespie argued for years that the GOP needed to be more expansive and welcoming to Latinos, should tamp down anti-immigration rhetoric and embrace comprehensive immigration reform.
"Look, we all have valid concerns about crime," Obama said. "We have legitimate concerns and even legitimate differences of how to manage immigration in a way that is orderly and fair. But the fact is crime and illegal immigration are as low as they've been in decades. And Ralph's opponent knows it. He has gone on record in the past, condemning the same kind of rhetoric that he's using right now."
"What he's really trying to deliver is fear. What he really believes is if you scare enough voters, you might score just enough votes to win an election," Obama said. "It's just as cynical as politics gets."
President Trump echoed the ads in a late-night tweet two weeks ago, in which he urged people to vote for Gillespie. Donald Trump Jr. also entered the fray this week to blast the media's coverage of the ads, tweeting that " 'Rape, Kill, Control' is literally MS-13's motto but they frame it as though it's racism."
Gillespie spokesman Dave Abrams said, "It's no surprise President Obama would level Lt. Gov. Northam's attacks against Ed at a Northam campaign event."
Other highlights of Obama's remarks:
Grappling with history
Obama waded into another explosive issue in the governor's race: whether to remove statues of Confederate leaders.
He did so in cautious, measured tones, never actually mentioning the statues but instead how to grapple with a flawed past.
And he did so in the former capital of the Confederacy, just a few miles from a boulevard marked by towering statues to political and military leaders from the losing side of the Civil War.
After this summer's deadly clashes in Charlottesville instigated by white nationalists rallying to protect a Confederate statue, Northam called on localities to relocate such monuments to museums and promised to be a vocal advocate for such an approach.
He has since backtracked and said localities should decide the fate of the statues. Republicans, sensing that Northam overstepped, have pounced, sending mailers and airing commercials criticizing him for wanting to "erase" history.
Obama struck back:
"Does anybody really believe that Ralph spent his whole life in the Old Dominion, and then he's going to run for governor and try to erase Virginia's history? That is not what this election is about. That is distraction. That is phony. That is divisive."
"Ralph believes if we talk about history, we are going to do it in a way that heals, not wounds," he said. "We shouldn't use the most painful parts of our history just to score political points."
He said Americans can honor historical figures for their contributions while recognizing their flaws, noting that Thomas Jefferson was a slave owner who wrote of the equality of men in the Declaration of Independence.
On a lighter note, Obama observed that his mother was distantly related to Jefferson Davis, the president of the Confederacy.
"Think about that," he said. "I bet he's spinning in his grave."
Shout-out to House of Delegates races
Obama, who has faced criticism for failing to build the strength of the Democratic Party during his two terms in the White House, urged the crowd to pay attention to the 100 seats up for election to the state House of Delegates.
He noted that 50 first-time Democratic candidates and a record number of women were running for office.
"So if you want a House of Delegates that looks more like Virginia and understands your life, then make sure to get out and vote for the whole ticket, not just a little bit of the ticket," he said.
'Democracy at stake'
Democratic turnout in off-year elections is usually low, and Obama implored the crowd to turn out, particularly younger voters.
"I think it's great that you hashtag and meme," Obama said. "But I need you to vote!"
"Y'all get a little sleepy. You get a little complacent. . . . As a consequence, folks wake up and they are surprised. How come we can't get things through Congress? How come we can't get things through the state House? Because you slept through the election!"
Obama wrapped up by underscoring what he said was riding on the Nov. 7 contest.
"We need you to take this seriously because our democracy is at stake, and it's at stake right here in Virginia," Obama said.