Spain's governing Socialists held a clear lead but will need support from smaller parties to stay in power after elections in which a far-right party made strong gains, results show.
After having two main political parties for decades, Spain's political landscape has fragmented into five parties.
Voters have been disillusioned as the country struggled with a recession, austerity cuts, corruption scandals, the divisive Catalan independence demands and a rise in far-right Spanish nationalism.
With two-thirds of the ballots counted, the Socialists led by Prime Minister Pedro Sanchez won nearly 30% of the vote on Sunday.
The far-right nationalist Vox party was poised to enter the lower house of Parliament for the first time with about 10% of the vote.
The tally means the Socialists won 126 seats in the 350-seat Congress of Deputies, while the far-left United We Can party captured 35 seats. That is still 15 seats short of the 176-seat majority needed to govern.
To remain in office, Mr Sanchez will have to form a governing alliance with smaller parties. He would likely turn to United We Can but will have to decide whether he wants to make pacts with Catalan and other separatist parties - a move that would anger many Spaniards.
Turnout in Sunday's vote was around 75%, up more than eight points since the previous election in 2016, the provisional results showed.
Polls a week ago showed that about one-third of Spain's nearly 37 million voters had not decided yet who to choose.
On the splintered right, three parties had competed for leadership: the once-dominant conservative Popular Party, the centre-right Citizens, and the nationalist, anti-migrant Vox party.
The arrival of Vox in Madrid's national parliament marks a big shift in Spain, where the far right has not played a significant role since the country's transition to democracy following the death of dictator General Francisco Franco in 1975.
Pablo Casado, who has steered the Popular Party further to the right to stop it from losing votes to Vox, called the ballot the country's "most decisive" in years.
Vox leader Santiago Abascal, who drew the largest crowds during campaigning, told reporters in Madrid that "millions of Spaniards are going to vote with hope, they are going to do it without fear for anything or anybody."
The surge in turnout included a huge boost in the north-eastern Catalonia region, which has been embroiled in a political quagmire since its failed secession bid in 2017 put several separatist leaders in jail while they undergo trial.
Speaking on Sunday after voting, Mr Sanchez said he wanted the ballot to yield a parliamentary majority that can undertake the key social and political reforms that Spain needs.
The prime minister said he wanted "a stable government that with calmness, serenity and resolution looks to the future and achieves the progress that our country needs in social justice, national harmony" and in fighting corruption.