Catalan separatist parties are on track to win most seats in the new regional parliament, setting the stage for more confrontation with Spain’s government.
However the Citizens party, which wants Catalonia to remain a semi-autonomous part of Spain, is the biggest party.
As a result, it is unclear who will be given the right to form a government.
The Madrid government stripped Catalonia of its autonomy and called the election after declaring an October independence referendum illegal.
With nearly all votes counted, the pro-independence parties Together for Catalonia (JxCat), Republican Left of Catalonia (ERC) and Popular Unity (CUP) were together on course to win a total of 70 seats, giving them a majority.
Within the separatist party block, ousted Catalan President Carles Puigdemont’s JxCat was slightly ahead of the ERC, led by his former deputy, Oriol Junqueras.
Speaking in Brussels, where he is in self-imposed exile, Mr Puigdemont said the “Catalan republic” had won and “the Spanish state has been defeated”.
The situation called for “rectification, reparation and restitution,” he said.
He is accused by Spanish prosecutors of rebellion and sedition. Mr Junqueras faces the same charges and is currently in prison.
Citizens (Cs) had 25% of the vote, winning 37 seats in the 135-seat chamber.
Its leader Inés Arrimadas told the BBC her party had been “victorious”. She said forming a coalition would be “difficult – but we will try”.
The Popular Party (PP) of Prime Minister Mariano Rajoy, who took the decision to remove Catalonia’s autonomy, was projected to win just three seats in the new Catalan parliament, down from 11 in the 2015 election.
Election turnout was more than 80%, a record for a Catalan regional election.
Why did the election take place?
Separatists who dominated the previous Catalan parliament declared independence on 27 October, after the referendum which was declared illegal by Spain.
In an attempt to stop that referendum, Spanish police stormed some polling stations. However many voters defied the Spanish courts and riot police to cast their ballots.
The move led to violent clashes with hundreds of people reported injured. Footage showing police tackling people at polling stations.
According to the organisers, 90% of voters were in favour of independence, but fewer than half the region’s electorate took part.
Mr Puigdemont decided it was enough to declare independence from Spain.
Mr Rajoy then sacked the Catalan government, imposed direct rule and called the 21 December election.
Prosecutors accused 13 Catalan separatist politicians of rebellion and sedition, including Mr Puigdemont and four others who fled to Belgium.
Among the accused, two pro-independence politicians are in Spanish prisons, and six are being monitored while on bail.
What has been the reaction?
The European Commission said that its stance towards Catalonia remained the same, despite Thursday’s election result.
The executive arm of the EU has previously stated that events in Catalonia are an internal issue for Spain.
“Our position on the question of Catalonia is well known and has been regularly restated, at all levels. It will not change,” commission spokesman Alexander Winterstein told AFP news agency.
“In relation to a regional election, we have no comment to make,” he added.
The Spanish government has not yet commented on the results.
What happens now?
Analysts say the success of separatist parties means that the ball is now back in the Spanish government’s court.
Antonio Barroso, of of the London-based research firm Teneo Intelligence, said the problem for Madrid remains “and the secession movement is not going to go away”.
Why do many Catalans want independence?
Catalonia is one of Spain’s wealthiest and most productive regions and has a distinct history dating back almost 1,000 years.
Before the Spanish Civil War it enjoyed broad autonomy but that was suppressed under Gen Francisco Franco’s dictatorship from 1939-75.
When Franco died, the region was granted autonomy again under the 1978 constitution, and the region prospered along with the rest of the new, democratic Spain.
A 2006 statute granted even greater powers, boosting Catalonia’s financial clout and describing it as a “nation”, but Spain’s Constitutional Court reversed much of this in 2010.
Recession and cuts in public spending fuelled local resentment, which coalesced in a powerful secessionist movement.
Following a trial referendum in November 2014, outlawed by Spain, separatists won the 2015 regional election and went on to win a full referendum on 1 October 2017, which was also banned and boycotted by unionists.