Croatia's top court said on Friday that the country's president, who had campaigned to become prime minister ahead of this week's parliamentary election, could not head the new government.
"The president has been warned in time that he cannot participate in the campaign, but that he must (first) resign. Now it is over. He can no longer be a prime minister-designate," Constitutional Court President Miroslav Separovic told a press conference.
"Everyone is obliged to adhere to the constitution and the law," he added.
Croatia voted in a parliamentary election on Wednesday in which the ruling conservative HDZ party won most of the seats, but not enough to form a government alone.
The vote was held after a bitter campaign between the country's longtime political foes -- conservative incumbent Prime Minister Andrej Plenkovic and left-wing populist President Zoran Milanovic.
For months, Plenkovic and his HDZ seemed poised for an easy victory that would secure his third term as premier.
But in mid-March Milanovic -- who tops political popularity surveys -- made the shock announcement that he would challenge Plenkovic and become candidate for the Social Democrats (SDP).
The Constitutional Court then immediately warned him that he could only stand in the election if he first stepped down as president.
But Milanovic ignored the warning and campaigned across the country accusing Plenkovic of leading the "most corrupt government in Croatia's history".
Corruption has long been the Achilles' heel of the HDZ, in power in Croatia for most of the time since its 1991 independence from Yugoslavia.
"I don't have to be a prime-minister designate," Milanovic told reporters Friday, accusing the court of preparing a coup.
The president said that although he considered himself an "optimal prime minister-designate... eventually it could be someone else. But these people (the HDZ) have to go".
The HDZ won 61 seats in the 151-member assembly and a centre-left coalition led by the SDP 42. The nationalist right-wing Homeland Movement party came third with 14 seats, making it a likely kingmaker.
Plenkovic said Thursday it would be known "very soon" with whom the party would form a new parliamentary majority.
But the SDP was also trying to cobble together a majority, although their task appears more difficult.
Its leader Pedja Grbin slammed the court's warning as "shameful" and said the tribunal "pissed on all of us... who voted" for a change.
In Croatia, the president names a prime minister-designate, backed by a majority of MPs, who is then voted on by the full parliament.
The elections were held as the European Union nation of 3.8 million people struggles with corruption, a labour shortage, the highest inflation rate in the eurozone and undocumented migration.