In the course of about six hours, what was supposed to be a Republican existential crisis turned into a Republican wave.

What was supposed to be a victory of the coalition of the ascendant became a dispiriting rout of the coalition that didn’t show up.

What was supposed to be the crowning political achievement of Barack Obama’s presidency set the predicate for the unraveling of his legacy.

Since before he was elected president, Obama put down as a marker the transformational example of Ronald Reagan. That entailed moving the political center of gravity of the country in his direction; winning re-election; and cementing his standing by securing a de facto third term for a Democratic successor.

As of 7 p.m. Tuesday, the Reagan standard looked to be in Obama’s grasp. His approval rating stood above 50 percent. He campaigned vigorously, and apparently effectively, in front of adoring crowds. The last round of public polling and the exit polls on Election Day showed Hillary Clinton getting over the top, and her victory seemed likely to precipitate an ugly, self-destructive Republican civil war.

By the wee hours of Wednesday, this scenario turned to ashes and Obama could only survey the wreckage of the Democratic Party, and by extension, his highest ambition.

Obama is a once-in-a-generation political athlete who will always be remembered as the nation’s first African-American president. But a goodly portion of what he has labored for over two terms could now wash out with the political tide.

His party has been devastated beneath him. It began in 2010, when Republicans took the House by winning 63 seats, the biggest pickup since 1948, and six seats in the Senate. In 2014, Republicans gained another 13 House seats and took control of the Senate. Democrats lost more than 900 state legislative seats in this period.

This was chalked up to the midterm effect, the product of a smaller, more Republican-leaning electorate in nonpresidential years. Well, on Tuesday night, the GOP won Senate races in blue states. It minimized losses in the House. It picked up more governorships, including in Vermont, and made striking gains in state legislatures from Kentucky to Connecticut.

All in a presidential year. The GOP controls the presidency, the US Senate and House, and roughly two-thirds of the country’s governorships and state legislatures. The Democrats are now, judging by the scorecard of major offices, the nation’s minority party.

What happened? From the beginning, Obama pushed the left-most plausible agenda without regard to political consequences. His signature initiative, ObamaCare, was forced through Congress despite its manifest unpopularity and with the crucial assistance of obvious falsehoods (i.e., that it would reduce premiums and people could keep their doctors).

When Obama’s initial legislative overreach cost him his congressional majorities, he proceeded with executive overreach, especially on environmental regulation and immigration. His attitude was that everyone had to get with his program and that if they didn’t, they were either stupid or spiteful. He believed less in the usual political arts of compromise and personal relationships than in the irresistible power of his own words.

Having made no real effort at party-building and after a series of disastrous midterms where his campaigning basically saved no one, he had no protégé to turn to in order to try to win his third term. The political bench was empty. He had to reach back to his vanquished rival, Hillary Clinton, whose inadequacies he had exposed in the 2008 primaries and who was almost comically ill-suited to energizing the Obama coalition.

Those voters were considered Obama’s enduring political contribution — an ever-growing bloc of minorities, millennials and the college-educated who would swamp older white voters and constitute an ideological ratchet, turning the country’s politics steadily to the left.

In its first big post-Obama test, the coalition failed. Now many of the president’s substantive achievements are under threat from a unified Republican government, especially ObamaCare, which is in a semi-crisis, and his vast number of unilateral actions. President Trump will pick up his own pen and phone.

President Obama’s party is lurching toward its own bloodletting after losing to perhaps the least likely presidential candidate in all of American history.

We now know that President Obama’s larger project has come a cropper. He is no Ronald Reagan, not even close.