Donald Trump captured Virginia’s Republican primary Tuesday, beating back a vigorous challenge from Sen. Marco Rubio of Florida in a key swing state and cementing his status as the leader for his party’s presidential nomination.

On the Democratic side, Hillary Clinton won a resounding victory, bolstering her place as the party’s front-runner as voters rejected the insurgent campaign of Sen. Bernie Sanders of Vermont.

While pre-primary polls showed Trump leading in Virginia by a wide margin, Rubio benefited from robust turnout in Northern Virginia, capturing twice the number of votes as the billionaire in the suburbs outside Washington, according to preliminary exit polls.

But Trump overwhelmed his competitors in more rural areas, including the Shenandoah Valley to the west and the Tidewater region in the south, and drew enough votes in the suburbs to emerge victorious.

Virginia primary exit poll results

Over the past generation, Virginia has evolved into an important bellwether in presidential elections, with its diverse population of blue-collar workers, suburban professionals and immigrants serving as a microcosm for the country.

Virginia was key in George W. Bush’s victories in 2000 and 2004. But the state went Democratic in 2008, with its burgeoning population in Northern Virginia helping to catapult Barack Obama to the presidency. That unpredictability has made Virginia an important prize for both parties heading into November.

Desperate for his first primary victory, Rubio devoted significant resources to the commonwealth in the days before voting, drawing support from high-income and highly educated Virginians as he hoped to emerge as the moderate alternative to Trump.

Rubio also performed well in the suburbs outside of Richmond, home to former Republican House majority leader Eric Cantor, who was unseated in 2014 by Rep. Dave Brat, a tea party upstart.

But Trump was able to hold off Rubio in part because Ohio Gov. John Kasich also took a significant number of votes in Northern Virginia, including 23 percent each in Arlington, Alexandria and Falls Church.

On the Democratic side, African Americans, voters older than 45 and those who favor candidates with experience propelled Clinton over Sanders. More than half of Democrats said they favor President Obama’s policies, which Clinton has promised to continue if she wins the White House.

Here are key moments from Democratic presidential candidates Hillary Clinton and Bernie Sanders's speeches, as results from Super Tuesday elections rolled in on March 1. (Sarah Parnass/The Washington Post)

Republican turnout across Virginia was record-breaking: roughly four times the level of 2012 and more than twice as many as voted in 2008, although both those contests were less competitive than Tuesday’s race. Democratic turnout was down, compared with 2008, the last time there was an open race for the White House.

In Arlington, poll workers ran out of Republican ballots and scrambled to make additional copies, registrar Linda Lindberg said.

Mike Lane, a veteran precinct captain in Alexandria, called the turnout “exceptional” and “incredibly unexpected.”

Clinton’s victory was also a win for Gov. Terry McAuliffe (D), a close friend of and fundraiser for the candidate and her husband, former president Bill Clinton. McAuliffe said the Democratic contest was notable for its civility, “unlike the divisive race to the bottom playing out on the other side.”

“Virginia Democrats were presented with a substantive choice about the future of our country,” he said. “Tonight they made the right one and helped bring Hillary Clinton another step closer to becoming our nominee and our president.”

But John Whitbeck, chairman of the state GOP, said that Clinton, despite her victory, had “real problems convincing voters she is trustworthy and the right leader for the country.”

Trump was counting on a victory in Virginia to build his delegate lead in the nominating process and add to the growing evidence that he appeals to a broad swath of Republicans, including blue-collar voters, college graduates and evangelical conservatives.

Clinton’s victory in Virginia is likely to help dispel doubts about her viability as the Democratic nominee and position her strongly for the fall contest.

In preliminary exit polls, more than 8 in 10 Virginia Democrats said they wanted a president who is a mainstream candidate, as opposed to someone outside the political establishment.

A third of the Democratic electorate identified “experience” as a key quality in a candidate, topping any other attribute.

“The momentum is clearly in Hillary’s direction,” said Mark Rozell, a political science professor at George Mason University. “The fact that voters are choosing experience over an outsider is so different than the Republican side right now — and that’s her calling card. In a year that’s supposed to be all about outsiders, she’s proving that experience still matters and that many voters want a certifiably qualified person as president.”

While Democrats in Virginia prized experience, Republicans were looking for a candidate to challenge the political establishment.

More than 1 in 3 Republicans said the quality they most want in a presidential candidate is an ability to “bring needed change,” according to preliminary exit polls.

Fewer than 2 in 10 Republicans said a candidate’s ability to win in November’s general election was the most important quality, and a similar share said they want a candidate who “tells it like it is.”

About 6 in 10 Virginia Republicans said that undocumented immigrants who are working should have a legal way of staying in the country, and a vast majority of those voters supported Rubio. Trump led by an even wider margin among voters who want to deport undocumented immigrants.

In interviews with The Washington Post over the past week, Trump’s supporters in the commonwealth repeatedly said they liked the billionaire for his ability to roil Washington. But an equal number — 3 in 10 — said they were seeking a candidate who “shares their values,” a theme that both Rubio and Sen. Ted Cruz of Texas stressed in their visits to the state.

“I think the change vote is one that is most important for Trump,” said Robert Holsworth, a retired Virginia Commonwealth University political science professor. “The big question is: How does Trump do in the Northern Virginia suburbs and the Richmond suburbs. For Republicans to win in November, Trump has to be a good candidate in the suburbs — and it’s an open question whether he is.”

As polls closed, Cruz and Kasich were fighting it out well below Trump and Rubio, jockeying for the third and fourth spots.

After voting in Prince William County, Jim Collins, 62, a building inspector, said he pulled the lever for Trump, even though he isn’t convinced that the billionaire will win in November.

“While he may not make the presidency, he’s definitely put things on the table that the other candidates have to address,” Collins said. “That’s what I like about him.”

At the Herndon Community Center, where a mix of Hispanic and Asian immigrants joined the growing stream of voters all morning, several Hispanic residents said they had chosen Clinton and were offended by the negative comments Trump had made about Mexicans and illegal immigrants.

Karen Gonzaga, 37, said she liked Trump, “but I’m not ready for him — he’s too extreme.” Instead, she voted for Rubio, in part because she thinks he would restore political peace in Washington.

“Everything is so chaotic now,” she said. “We have to be a democracy and talk to each other.”

Correction: Some earlier versions of this article gave incorrect information for how many votes Ohio Gov. John Kasich (R) won in specific Northern Virginia jurisdictions. The article has been corrected.

Scott Clement contributed to this report.