Democrat Terry McAuliffe edged out Virginia attorney general Ken Cuccinelli in the race to be the state’s next governor on Tuesday, riding a significant financial advantage and voter distaste over the Republican’s staunchly conservative stances on social issues to victory in the key swing state.

The contest was close late into Tuesday night after polls had indicated McAuliffe, a former Democratic National Committee chairman and close Clinton confidante, could win by high single digits. But with 96% of precincts reporting, McAuliffe led Cuccinelli 47.1% to 46.3%, and the Associated Press called the race for McAuliffe at about 10 p.m. E.T. A third candidate, libertarian Robert Sarvis, ended up winning a critical 6.7%.

It’s the first time the party occupying the White House has won the state’s off-year gubernatorial election since 1973.

McAuliffe, a longtime party moneyman, raised almost $15 million more than Cuccinelli, and almost $35 million overall, according to the Virginia Public Access Project. McAuliffe spent more in every media market in Virginia, and over the past four months, when he led in every major poll, his campaign has spent more than his opponent’s 12 out of those 15 weeks, according to the Washington Post.

His air assault helped portray Cuccinelli as an extreme candidate on social issues, especially on same-sex marriage, abortion and contraception. That led to a considerable gender gap, with McAuliffe outperforming Cuccinelli among suburban women, who are key to winning elections in the state.

“His entire strategy has been to mislead Virginians — particularly women — about my record,” Cuccinelli complained of McAuliffe in a Politico op-ed the day before the election.

Polls showed that voters viewed both candidates negatively. But in the end, as one Virginia businessman told TIME in July, McAuliffe was the lesser of two evils.

A recent Post poll showed that voters in fact cared more about transportation than ethical issues, to McAuliffe’s further benefit; he backed the state’s bipartisan transportation law, while Cuccinelli opposed it.

In the final weeks before Election Day, both candidates trotted out star supporters to rise above the mud. McAuliffe called in President Barack Obama, Vice President Joe Biden and old pal former President Bill Clinton. Hillary Clinton, a possible 2016 presidential candidate, made her first campaign appearance in nearly five years to support McAuliffe, who co-chaired her husband’s 1996 re-election campaign and chaired her 2008 campaign.

Cuccinelli, meanwhile, saw visits from Senators Marco Rubio, Rand Paul and Ted Cruz, as well as former Representative Ron Paul. But Ron Paul, the libertarian icon, failed to stanch the bleeding of support to Sarvis, who proved a significant spoiler in the race. Cuccinelli, who tried to make the bungled rollout of Obama’s health care law a key issue, ended up being more hurt by the government shutdown in a state where the economy is heavily reliant on government spending.