In a vote that made nonsense of polls that had predicted a close result, the Conservatives appeared to have gained more than 20 seats to advance just over the magic number of 326 that confers a parliamentary majority. Labour, vanquished by the S.N.P. in its former Scottish stronghold, plunged by more than two dozen seats. The S.N.P. turned Scotland into something resembling a one-party state, taking 56 of 59 seats. The Liberal Democrats, Cameron’s coalition partners over the past five years, were all but wiped out, and the anti-immigrant U.K. Independence Party appeared to have secured only a couple of seats even as its vote share grew.

Miliband said he was “deeply sorry” about what had happened, calling the outcome “difficult and disappointing.” Those Labour difficulties will not disappear quickly. The seismic change in Scotland, eclipsing the party, will make it very difficult for Labour ever to win a British majority unless the surge of support for Scottish independence somehow abates.

Labour, revived by Tony Blair in the 1990s and invincible for more than a decade, is firmly back in the political wilderness. Miliband’s push leftward, away from the center ground favored by his brother David, the former foreign secretary, proved disastrous. For now, it is unclear how the party will revive itself.

Scottish independence, rejected last year in a referendum, moved closer to reality through this election, whatever Cameron’s promises of a further devolution of powers.

Cameron’s victory, after a lackluster campaign that earned him more criticism than praise, was a personal triumph, but he will not be able to bask in its glow for long. At best, he will have a tiny majority. He may have to call on outside support, possibly from Northern Ireland’s Democratic Unionist Party, which won eight seats. The comfortable majority of his current coalition has gone. On the other hand, he is freed from the Liberal Democrats, whose staunchly pro-European views never sat comfortably with the Tories.