Former president Barack Obama returned to the campaign trail on Thursday to deliver a catharsis to a raucous crowd of thousands despondent over the presidency of Donald Trump. And he sought to channel their frustrations into electing Democrat Ralph Northam in Virginia's high-stakes gubernatorial election that is just three weeks away.

Obama never named his successor or Northam’s Republican opponent, Ed Gillespie, once in a 34-minute speech. But he seemed to be referring to both men as he lamented how politics have turned “nasty.”

“We’ve got folks who are deliberately trying to make folks angry, to demonize people who have different ideas, to get the base all riled up because it provides a short-term tactical advantage,” Obama told the 7,500 people gathered in the Greater Richmond Convention Center. “So the question for you tonight for the next 19 days: Do you want a politics of division and distraction, or do you believe in a better kind of politics?”

He praised Northam, a former Army doctor, pediatric neurologist and current lieutenant governor, as the kind of leader the country needs.

“At a time so many of us are cynical about government and public service, to have someone step up who you can trust and just wants to do right by the people of Virginia, that’s worth something,” said Obama, who in 2008 became the first Democrat to carry Virginia in a presidential race in 44 years.

Former US President Barack Obama speaks during a campaign rally for Democratic Gubernatorial Candidate Ralph Northam R) in Richmond, Virginia October 19, 2017. / AFP PHOTO / JIM WATSONJIM WATSON/AFP/Getty Images (Jim Watson/AFP/Getty Images)

Northam is locked in a tight contest with Gillespie, a longtime GOP operative and former chairman of the Republican National Committee.

Obama’s presence seemed to animate Northam, a normally low-key, genteel man who was visibly emotional and at his most energized since he launched his campaign two years ago.

“Unfortunately, my opponent Ed Gillespie is cut from the same cloth that Donald Trump is,” said Northam in his booming Eastern Shore drawl. “He is nothing more than a Washington lobbyist who has now become Donald Trump’s chief lobbyist. We cannot let that happen in the commonwealth of Virginia. All of us need to stand up on Election Day. We cannot accept this is the new normal.”

Obama’s appearance in Richmond came hours after he also campaigned for Democratic gubernatorial nominee Phil Murphy in New Jersey — the only other state electing a new governor this year.

The latest stories and details on the 2017 Virginia general election and race for governor.

The Virginia race is broadly seen as a hint of what's to come in next year's midterm elections. A Democratic defeat in a purple state that voted for Hillary Clinton last year would be a devastating blow to a party hoping to convert anger toward Trump into electoral success.

Richmond is part of the “urban crescent” that stretches from the D.C. suburbs to Hampton Roads, a densely populated slice of the state where Democrats have successfully driven up margins to win statewide elections since 2009.

The city also has a significant African American population, a key Democratic constituency — and a large portion of the 7,500 people gathered at the Obama-Northam rally were black. Black voters make up nearly a fifth of the state’s electorate and are crucial to Democratic success on Election Day.

Obama’s appearance comes the same week as intraparty tensions among the Democrats threatened to alienate black voters.

Northam’s campaign paid for the production and distribution of 1,000 palm cards that included photos of him and Attorney General Mark R. Herring (D) but not their ticket mate, Justin Fairfax, who is running for lieutenant governor and hopes to become the first African American elected statewide in more than 25 years. The omission was requested by a union distributing those palm cards that did not endorse Fairfax.

While the fliers in question were a sliver of all campaign literature, the perceived snub made its rounds on social media, and several black activists touted it as an example of Democrats taking the African American vote for granted. Fairfax called out the Northam campaign for what he called a “mistake” and urged the party to renew its focus on engaging black voters.

Enter the nation’s first African American president.

Obama made frequent references to Fairfax, bolstering his bid for lieutenant governor.

“He didn’t grow up with much, but with scholarships, a hard-working mom, he went to college and law school and chose public service to make sure other striving young kids could have the same opportunities,” Obama said.

Though he was speaking to Virginia voters on Thursday, Obama seemed to be addressing the whole country as he offered an optimistic vision for politics and a defense of the fundamental decency of the American people.

The question before voters, Obama said, is “at a time when our politics just seem so divided and so angry and so nasty, it’s whether we can recapture that spirit, whether we support and embrace somebody who wants to bring people together.”

“Yes we can,” he said, repeating his 2008 campaign slogan and triggering the crowd to chant the phrase in response. “We can do that.”

“President Obama spoke to my heart,” said Dorothy Ware, a 66-year-old retiree in Chesterfield County outside of Richmond. “We want a united United States, not the crap that’s going on now. That’s what we’ll get with this man right now,” holding up a Northam sign.

Dionne Jennings, 48, said Obama’s speech impressed upon her the urgency of a race that seemed low-key to her until now.

“This is going to inspire people to be more active,” said Jennings, of Prince Edward County in central Virginia. “The way society is going right now, we need some help. Everything he said made that point. We’re going to continue that work.”

Ruth Twiggs of Richmond waited in line with two friends and acknowledged that energy levels in the Northam campaign may have been low through the summer.

“I think people were exhausted from last year,” she said.

“I think part of it is [Northam’s] personality,” added her friend Anne Barriault, 65, also of Richmond. “He’s low-key, which is okay.”

“It’s a relief — sane and low-key,” Twiggs said. “This is good.”

The final weeks of the Virginia election have seen their share of party all-stars.

On Saturday, the current and former vice presidents joined the campaign fray. Former vice president Joe Biden (D) appeared at an economic roundtable with Northam to praise his workforce development plan. Hours later, Vice President Pence (R) rallied a crowd of about 600 for Gillespie in deep-red Abingdon in southwest Virginia.

Another former president, George W. Bush, on Monday headlined a pair of Virginia fundraisers for Gillespie, who served as his White House counsel and chairman of the Republican National Committee. Hillary Clinton helped Northam fundraise in New York earlier this month.

It’s unclear whether Trump will appear with Gillespie in a state where he’s deeply unpopular.

Gillespie has struggled to find the right footing regarding Trump. He needs to excite Trump voters in southwest and Southside Virginia without alienating moderates and independents who are necessary to beat Northam. Trump endorsed Gillespie in a tweet two weeks ago, but Gillespie did not mention it until pressed by reporters the following day and has not included it on his campaign materials.

But since September, Gillespie has been embracing issues that resonate with Trump voters, airing ads that defend Confederate statues and tie MS-13 gang violence to illegal immigration.

At Thursday’s rally, Obama called Gillespie’s ads as “cynical as they get.”

“What he’s really trying to deliver is fear,” Obama said. “If you scare enough voters, you might score just enough votes to win an election. That’s what makes this . . . damaging to our democracy.”