Mr. Cuccinelli, Virginia’s attorney general, lost by only 2.5 percentage points – 48 percent to 45.5 percent – a far narrower margin than in most of the race’s final polls. If last month’s tea party-fueled government shutdown was the final nail in the coffin for Cuccinelli, the disastrous rollout of HealthCare.gov almost brought him back to life.

The narrowness of the loss in Virginia provides cold comfort to Republicans, who have ceded control of a critical presidential battleground state to a close friend of the Clintons – an asset to Hillary Rodham Clinton if she runs for president.

Taken together, New Jersey and Virginia provide lessons for the Republicans nationally, political analysts say.

Take abortion. Governor Christie opposes abortion rights in a state where a majority supports them, but it’s not a defining issue for him. In Virginia, Cuccinelli’s strong opposition to abortion – including support for a failed measure that would have required a vaginal ultrasound before an abortion and a new law putting significant restrictions on abortion clinics – put him out of step with unmarried women in his state, a key voting bloc.

Mr. McAuliffe won the women’s vote overall by 9 points and unmarried women by 42 points, while losing married women by 9 points. One out of four Virginia women voters – and 14 percent of men – called abortion the most important issue in the race, according to the exit poll. Among these “abortion voters,” McAuliffe beat Cuccinelli 2 to 1.

“It’s not simply that these are liberal women,” says Bob Holsworth, a principal in the public policy firm DecideSmart. The abortion restrictions “are seen by women as government overreach, which is what Republicans are supposedly criticizing.”

But Virginia turned on far more than the abortion issue. A political gift scandal sidelined the state’s current governor, Republican Bob McDonnell, from the campaign. Cuccinelli, too, had taken gifts from the same business executive, and in September donated the equivalent in cash to charity, an embarrassing episode just two months before the election.

Cuccinelli’s profile as a skeptic on manmade global warming also hurt him, especially among young voters. Ditto his opposition to gay rights. He was tagged as an ideologue from the start, and that scared off some in Virginia’s business community – and donors. McAuliffe, a former chairman of the Democratic National Committee and master fundraiser, outraised Cuccinelli almost 2 to 1. The Republican was hard-pressed to fight back dollar for dollar on the airwaves in a race marked by mudslinging on both sides.

Cuccinelli’s candidacy was controversial from the start. The state GOP opted to nominate its candidates not via a primary but in a convention, which attracts the most motivated activists, i.e., tea party conservatives. Virginia’s popular Republican lieutenant governor, Bill Bolling, was left out in the cold. Mr. Bolling contemplated an independent candidacy, but opted out.

“He’s definitely kicking himself right now,” says Republican strategist Ford O’Connell, author of the new book “Hail Mary: The 10-Step Playbook for Republican Recovery.”

Instead, a young software developer named Robert Sarvis won the Libertarian Party nomination, and garnered 6.6 percent of the vote. He was seen mostly as a protest candidate, a haven for voters unimpressed with either of the major-party nominees, but who took more from Cuccinelli than McAuliffe.

“You had the weakest Democrat in a generation and a tradition of voting against the president’s party nine straight times. This should have been an easy one for Republicans,” says former Congressman Davis. “They decided, all you needed was the label, and it didn’t work.”

McAuliffe, a wealthy businessman, had run for governor four years ago, but lost in the Democratic primary. The Cuccinelli campaign tried to portray the Syracuse, N.Y., native as a glad-handing carpetbagger, but that wasn’t enough. Analysts saw the race mostly as a referendum on Cuccinelli, not an endorsement of McAuliffe.

McAuliffe, in fact, is out of touch with much of the state in his support for gun restrictions, gay marriage, and federal environmental regulations on coal-fired plants. Virginia is an important coal state.

Religious conservative activists in the state reject the idea that Cuccinelli’s social views gave him a losing hand. What killed him was his failure to defend himself against McAuliffe’s “lies” about his positions and unwillingness to go after McAuliffe’s support for abortion “at any time and for any reason,” says Gary Bauer, president of the group American Values.

Cuccinelli “did not hedge on the fact that he was pro-life, but he failed to aggressively identify the extremism, the cultural and social extremism, of the candidate he was running against,” says Mr. Bauer, referring to McAuliffe’s broad support for abortion rights.

Perhaps most stunning for Cuccinelli is the fall of his rising star in the conservative Republican firmament. Just three years ago, at a Richmond, Va., convention of the Virginia Tea Party Patriot Federation, Cuccinelli was the big attraction. Supporters handed out yellow “Cuccinelli for President” stickers.

Indeed, just like Christie in New Jersey, Cuccinelli seemed poised to make a gubernatorial victory in 2013 a stepping-stone to a presidential campaign. He published a book, “No Apologies,” an uncompromising attack on government and on President Obama, and has visited the earliest nominating states, Iowa and New Hampshire.

But unlike Christie, a pragmatist whose blowout reelection victory on Tuesday puts the wind at his back, Cuccinelli joins the ranks of tea-party backed Republican candidates who fell short.