MADRID — Spaniards struggling with high unemployment and a credit squeeze delivered a punishing verdict on almost eight years of Socialist government at the ballot box on Sunday, turning to the conservative Popular Party in the hopes of alleviating the pain of Europe’s debt crisis.

With 99.8 percent of the vote counted Sunday night, the Popular Party, led by Mariano Rajoy, had won 186 seats and a governing majority in the 350-seat lower house of Parliament, while the governing Socialists plummeted to 110 seats from 169. It was the Popular Party’s best showing, and the Socialists’ worst, since Spain’s return to democracy in the 1970s.

Spain is the third southern European country in two weeks to see its government felled by the debt crisis in the euro zone. In Italy and Greece, prime ministers were forced by mounting financial and economic woes to resign and give way to interim “unity” governments of technical experts, who are meant to take urgent but unpopular austerity measures to cope with the crisis and then call new elections.

The new Spanish prime minister will have an advantage they lack — the solid backing of a freshly elected single-party majority in Parliament — but he must still cope with the same dire combination of economic stagnation, gaping budget deficits and crushing debts that brought down his predecessor, and that swept governing parties out of office in Greece and Italy this month, Portugal in June and Ireland in February.