Republican Ed Gillespie and Democratic Lieutenant Governor Ralph Northam are running in this year's closely watched race for Virginia governor. (Claritza Jimenez/The Washington Post)

The national spotlight swung to Virginia on Tuesday as voters came out for the country’s first swing-state test of how candidates of both parties will combat, embrace or finesse President Donald Trump’s fierce populism one year after it propelled him into the White House.

Virginians woke to a cold, wet election day having endured an increasingly negative campaign that many said left them exhausted and dismayed. Rain fell steadily in the northern, more populous part of the state and was not expected to taper significantly before polls closed at 7 p.m.

Trump himself weighed in repeatedly during the day on behalf of GOP nominee Ed Gillespie, a long-time establishment Republican who distanced himself from the president personally while adopting some of his culture war stylings late in the campaign. In television ads, Gillespie slammed Democrat Ralph Northam as soft on crime and the Salvadoran gang MS-13, an attack Trump repeated by Twitter from Asia:

“Ralph Northam will allow crime to be rampant in Virginia,” Trump wrote on Twitter. If the Republican wins, Trump said, “MS-13 and crime will be gone.”

Preliminary exit poll results show just over 4 in 10 Virginia voters approving of President Trump’s job performance, a bit higher than some pre-election polls but still underwater, with a majority of voters disapproving. Roughly half of voters say Trump is “not a factor” in their vote, but among the remainder, about twice as many say they intend to “express opposition” to Trump as “express support.” That margin is similar to a Post-Schar School poll earlier this fall.

Trump recorded a robo-call received in some voters’ homes late Monday and into Tuesday. “Northam is weak on crime, weak on immigration, and as your lieutenant governor, Northam has driven your economy right into a ditch, and he didn’t even show up to the most important meetings,” the president, according to a transcript obtained by Politico.

“The voicemail was very Trump,” said Marvin McFeaters, 72, who had saved the call on his flip phone and played it again just after voting for Gillespie in Falls Church. The retired Vietnam War veteran wants to curb illegal immigration, though he is a “big believer in legal immigration” and is married to a naturalized citizen. He had not seen Gillespie ads that linked Northam to MS-13 and pedophilia.

Former President Barack Obama also recorded a robo-call on Northam’s behalf and campaigned in Richmond for him last month, the most prominent of several high-profile African American Democrats who have stumped for the Democrat, including Sens. Cory Booker (N.J.) and Kamala D. Harris (Calif.).

Democrats have appeared to have an edge over Republicans in party identification among Virginia voters, according to preliminary exit poll results. Just under 4 in 10 voters identified as Democrats while just over 3 in 10 identified as Republicans.

Voters brought competing outrages to the polls. A backlash against Gillespie ads seemed to have inspired some Democratic voters to turn out for Northam. But many Gillespie supporters said they were likewise offended by a pro-Northam ad from the group Latino Victory Fund that depicted a Gillespie supporter in a truck chasing minority children.

The president “got me here at six in the morning,” said Drew Bendon, 53, of Arlington. The stay-at-home father said he was “disappointed” by Gillespie’s campaign, in particular the MS-13 ads which seemed to equate illegal immigrants with violent criminals.

“Especially after Charlottesville, it’s dangerous to conflate gang activity and the way a person looks,” he said.

Exit poll results: How different groups voted in the 2017 Virginia governor election

Yani Portillo, 50, voted in a gubernatorial race for the first time, supporting the Democratic ticket.

“I wanted the Republicans out,” said Portillo, of Springfield. “It’s not right for the country to have this environment where there’s hate, where there’s just a lot of negative one-against-the-other type of thing . . . I thought I should do my part to put my little grain of salt.”

Margaret Patterson, 29, a lawyer from Arlington, said Gillespie’s campaign convinced her to vote Democratic.

The negative advertising “influenced me to vote, probably in the opposite way it intended me to,” she said.

But Patterson’s husband, Hunter Patterson, 29, was turned off by the other negative ad: the Latino Victory Fund campaign’s spot against Gillespie.

“I wanted to send a clear message that not all Republicans” are racists, he said.

Michelle Villado, 44, a government contractor from Arlington, said she, too, felt compelled to vote against Northam because he “didn’t speak against” the Latino Victory Fund ad.

“I wasn’t going to come vote,” said Villado, a libertarian who did not vote in 2016, but “I felt the need to vote for the other guy.”

Both campaigns struggled to navigate a political landscape that has been transformed in the age of Trump. Gillespie, a former head of the Republican National Committee, was pushed far out of his establishment comfort zone by a surprisingly strong challenge in the GOP primary by hard-right Trumpian candidate Corey Stewart, the chairman of the Prince William County Board of Supervisors.

Northam, a low-key former Army doctor and current lieutenant governor, ran an appeal to the traditional Democratic coalition even as the party remains roiled by progressive voters who supported Sen. Bernie Sanders in the 2016 presidential race and former Congressman Tom Perriello in the gubernatorial primary.

Many voters said Tuesday they were not enthusiastic about either candidate.

“As usual I had to vote against someone,” said Bill Miller ,67, a retired federal government employee from Arlington. “Against Gillespie because I have familiarity with the Republican machine and he’s still part of it.”

At Fairview Elementary School in Fairfax Station, Philip Barry voted for Gillespie and Republicans down the ballot but decried the tone of the campaign on both sides.

“I don’t like the hate speech that’s in our commercials,” said the marketing and business majore at Northern Virginia Community College who turned 21 on election day.

He was one voter who went with the GOP in part over his lingering distaste for Democratic standard bearer Hilary Clinton. Others considered this vote a referendum on Trump.

“We have to get rid of Trump and the best way to do that is at the local level,” said

Robyn Kamerling, a 60-year-old self-employed contractor from Ashburn.

Across the state, the attacks and retorts played out in voters’ mind as the prepared to cast their ballots. Robert Kinsler, 33, a business owner in Alexandria, was also incensed by the Latino Victory Fund ad.

“I thought the ad was very despicable and pushed me over the edge. It played to the common refrain from the left that the right is evil,” Kinsler said as he finished voting at Alexandria Fire Station #204. “It’s just very low.”

Kinsler’s vote for Gillespie was driven in part by his opposition to sanctuary cities.

Barbara Cottman, 73, a retired nurse and Trump supporter, said the same.

“I believe in Make America First,” said Cottman, who is African American and lives in Woodbridge. Sanctuary cities, she said, are “spitting in the president’s face.”

Virginia does not have any sanctuary cities, and Northam has said he opposes them.

Some minority voters, meanwhile, expressed the same fears that the Latino Victory Fund ad invoked.

“We have children, and we want to raise them in a place where they feel safe and secure,” said Ridaa Chippa, who voted in Arlington. She and her husband, Hamaad, who now live in Fairfax, said they worry that anti-Muslim bias could increase if Gillespie wins.

Jose Marquez, 54, voted in Woodbridge with his American-born son, a 23-year-old college student. Marquez, who works in construction and lives in Woodbridge, came to the United States when he was 18, fleeing El Salvador’s brutal civil war. He became a citizen in 1995 and said he has voted ever since.

He said he is deeply concerned about racism in Virginia and discrimination against immigrants. By alienating Latinos and immigrants, he said, the Republican Party is contributing to its own demise.

“It’s breaking them,” he said.

Kamran Atabaki, 69, disagreed. The Falls Church voter and real estate broker, who immigrated from Iran in 1970, said he was “not living in the United States to be a socialist or a communist.”

Atabaki, who campaigned for Trump last year, said he appreciated Gillespie’s commitment to cracking down on gang violence.

“All I want is to punish the bad people and the criminals,” Atabaki said. “I have a six-month old granddaughter, and I want the world to be a better place for her.”

Virginia’s gubernatorial election is typically a low-turnout event. But while rain may keep some home, there are indicators that this matchup is drawing more voters than usual for an off-year contest.

Several poll workers in Northern Virginia said they were seeing heavier morning traffic than they did four years ago.

“We have a lot of early voters,” said Allyn Hammel, the chief election officer at West Springfield High School. “This is busier than I expected it to be.”

At Kerrydale Elementary School in Woodbridge, poll chief David Ogbonlowo said 470 of 3,397 registered voters had cast their ballots by 11 a.m.

“Some elections we never had half of that,” by that hour, he said.

The election has set a record for absentee voting. The more than 147,000 absentee votes cast as of Friday night were the most for a nonpresidential year in Virginia history.

A record amount of money has been spent on the three statewide contests for governor, lieutenant governor and attorney general, and both Democrats and Republicans say their volunteers have doubled or tripled the number of home visits, phone calls and text messaging to get voters to turn out, compared with the 2013 governor’s race.

Northam and the Democrats are concentrating on a deep-blue urban crescent that runs from Northern Virginia to Richmond and Hampton Roads and has been key to Democratic wins for statewide offices since 2009.

Gillespie has been courting Republicans in white rural Southwest and Southside Virginia but also needs to peel away moderates and independents. He particularly needs votes in Northern Virginia, where he lives, to overcome Northam’s built-in advantage with Democrats in the most populous part of the state.

African American voters are an important bloc for Democrats and have been pivotal in their ability to win statewide elections. Northam comes from Hampton Roads, home to a large African American population, and is backed by scores of black elected officials statewide, relationships that he cultivated over 10 years as a state lawmaker and lieutenant governor.

Still, a misstep earlier this month by the Northam campaign — it omitted Justin Fairfax, the African American Democrat running for lieutenant governor, from some campaign literature funded by a union that endorsed Northam but not Fairfax — sparked criticism that the Democrats were taking the black vote for granted.

In eastern Henrico County, however, where Democrats have targeted African American voters, poll workers said turnout so far was about average.

Angela Canty, 49, said she was not enthusiastic about this year’s candidates but felt motivated to vote in opposition to Trump.

“I just feel like he has cast such a negative on the Republican Party,” said Canty, a health-care worker. “It’s the worst it’s ever been.”

Gillespie, a former lobbyist, chairman of the Republican National Committee and White House counselor to President George W. Bush, nearly beat Sen. Mark R. Warner (D) in 2014, and he emerged from that contest with newfound stature and name recognition. But running for governor this year, Gillespie nearly lost the June GOP primary to Corey A. Stewart, who ran a surprisingly strong campaign in the Trump mold in which he celebrated Confederate statues and called for a crackdown on illegal immigration.

After the primary, Gillespie struggled for months to strike the right posture toward Trump. He tried to avoid reacting to the daily barrage of Trump controversies, often bypassing the mainstream media in favor of controlled appearances before friendly groups he could later trumpet on social media. He reacted gingerly last month when the president tweeted an endorsement.

But from his initial emphasis on the economy and taxes, Gillespie steered toward cultural issues such as illegal immigration and Confederate statues — a strategy that polling suggests helped him firm up support among conservatives.

Carol Fox, 67, said she worried Gillespie didn’t do enough.

“He should’ve gone to Corey Stewart, buried the hatchet and got Corey to go out and get the Trump voters,” the Republican activist said before voting in Prince William County.

Libertarian Cliff Hyra is also on the ballot, but he has been registering in the low single digits.

Voters will also choose between Fairfax and Republican state Sen. Jill Holtzman Vogel for lieutenant governor, and between Republican John Adams and Democratic incumbent Mark Herring for attorney general.

Besides the statewide races, all 100 seats in the House of Delegates are on the ballot. A record number of Democrats are running, including a record number of women.

Republicans have a 66-34 advantage in the House; Democrats would need to flip 17 seats to win control. They are focusing their efforts on 17 legislative districts represented by Republicans but carried by Democratic presidential nominee Hillary Clinton last fall. Still, many of those districts are in exurbs where minorities and millennials vote Democratic in presidential races but historically don’t show up for state races the following year.

Of all the delegate races, the contest that has attracted national attention is in Prince William County, where Democrat Danica Roem, a transgender woman and former journalist, is challenging conservative GOP Del. Bob Marshall, the sponsor of unsuccessful legislation that would require transgender people to use the bathroom that corresponds to their gender at birth. Marshall, who refers to Roem as “he,” has refused to debate her. Clinton carried his district by 14 points in 2016.

Another race that has received wide attention is in Southwest Virginia between Republican incumbent Joseph Yost and Democrat Chris Hurst, a former news anchor whose girlfriend, reporter Alison Parker, was fatally shot in 2015 on live television.

Polls close at 7 p.m.

steve.hendrix@washpost.com

Patricia Sullivan, Rachel Chason, Sarah Gibson, Kristen Griffith, Antonio Olivo, Maria Sacchetti, Gregory S. Schneider, Shira Stein, Laura Vozzella and Julie Zauzmer contributed to this report.