The ruling Popular Party has lost command of the parliament
The future of Spain's prime minister appears uncertain after his party fell well short of an overall majority in the country's election.
The ruling Popular Party (PP) won most seats but lost command of the parliament after a strong showing by two smaller parties.
Spain's political scene is traditionally dominated by the Conservatives and the Socialists - they have alternated power for more than 30 years.
However the business-friendly Ciudadanos and far-left anti-austerity Podemos managed to tempt significant numbers of voters.
With 99.9% of votes counted, the PP won just 123 seats in the 350-seat lower house, 63 fewer than four years ago.
The Socialists got 90 seats; Podemos and its allies won 69; Ciudadanos won 40.
Podemos' leader - Pablo Iglesias - hailed the result as the end of 'two party' politics in Spain.
Negotiations - potentially lasting weeks - are now on the horizon as parties look to enter a coalition and form a government.
It is thought the PP will struggle to form a coalition, as entering into a deal with Ciudadanos - its closest political match - would still not give it enough seats.
Despite what looks like an uphill task, Mariano Rajoy told his cheering supporters that his party is "still the number one force in Spain".
Socialist leader Pedro Sanchez said that "Spain wants a move to the left".
His party could look to Podemos and Ciudadanos to form a so-called "coalition of losers".
Voter turnout was up - at 73.2% - as people looked to have their say on a country that is struggling with unemployment of 21%, a string of corruption scandals, and the growing calls of independence from Catalonia.
Mr Rajoy has promised to defeat the growing calls for separatism from the region - seen as the biggest threat to Spanish unity in decades.
The current government has already passed next year's budget and there are hopes cheap oil and low interest rates should keep the economy ticking along and calm market concerns if coalition talks drag on.
However, should the political wrangling last too long, another election could be called and pro-independence Catalan parties could also use any deadlock to push their cause higher on the national agenda.
Fiona Govan is the editor of the English language newspaper The Local in Madrid.
She told Newstalk Breakfast a coalition between the Popular Party and the Socialists would be unworkable.