A historically fragmented vote in Spanish elections on Sunday heralded weeks of talks to form a coalition government, with neither Prime Minister Mariano Rajoy's conservatives nor left-wing parties winning a clear mandate to govern.

Despite garnering the most votes, the center-right People's Party (PP) had its worst result ever in a general election as Spaniards angered by high-level corruption cases and soaring unemployment turned away from the party in droves.

In Spain, the fragmented vote heralded a new era of pact-making, shattering a two-party system that has dominated Spain since the 1970s and casting a pall over an economic reform program that has helped pull the country out of recession.

"We're starting a period that will not be easy," Rajoy told cheering supporters from the balcony of the party headquarters in central Madrid. "It will be necessary to reach pacts and agreements and I will try to do this."

However, the likelihood of a PP-led coalition faded with the robust showing of Podemos who roared into third place, outpacing fellow newcomer Ciudadanos whose market-friendly policies had been seen as a natural fit for the PP.

A tie-up between the PP and Ciudadanos would yield 163 seats, far short of the 176 needed for a majority administration.

The strong results of anti-austerity party Podemos tipped the balance to the left of the political spectrum with five left-wing parties led by the opposition Socialists and Podemos together winning 172 seats.

Such a left-wing alliance will be hard to form, however, as groups differ on economic policy and the degree of autonomy that should be awarded to the wealthy northeastern region Catalonia, home to an entrenched independence movement.

"This result confirms Spain has entered an era of political fragmentation," said Teneo Intelligence analyst Antonio Barroso. "The key question is whether there will be a coalition of parties against Rajoy."

The Spanish constitution does not set a specific deadline to form a government after the election. Analysts say negotiations to secure enough parliamentary support for a new prime minister could go for weeks - and maybe trigger another election.

Leader of the opposition Socialists, Pedro Sanchez, said on Sunday Rajoy had the right to have a first go at forming a government as he had won the most votes.

A minority PP government would be technically possible but unlikely due to the strong left-wing vote, as would be a grand coalition between the PP and the Socialists, which both parties vehemently ruled out during campaigning.