The constitutional court in Turkey has annulled last Friday's parliamentary vote to elect a new president.
The court ruled there was not a quorum for the vote
The only candidate, Foreign Minister Abdullah Gul, failed to win the required majority after a boycott by secularist opposition parties.
The parties, which accuse Mr Gul of a hidden Islamist agenda, asked the court to rule that there was no quorum.
The government vowed to restart the election process on Wednesday but it was unclear what form that would take.
Government spokesman Cemil Cicek said the ruling AK party would propose its candidate again.
But another ruling party lawmaker, Sadullah Ergin, said only a timetable for a new vote would be set.
The constitutional court backed the opposition's argument that a quorum of two-thirds of the 550 lawmakers was not present for Friday's vote. Its ruling cannot be appealed.
A total of 361 lawmakers voted - 357 for Mr Gul - but 367 were needed to make a quorum.
Abdullah Gul was just short of the required majority
After the ruling, Mr Cicek said the government would be prepared to meet an opposition call for an early general election provided parliament agreed to lower the age limit for MPs to 25.
AK believes this will boost its electoral chances.
Mr Gul and Mr Erdogan are both from AK, which has Islamist roots and an overwhelming majority in parliament. They deny there is any hidden agenda.
But the BBC's Sarah Rainsford in Istanbul says the army had made it clear it would not tolerate Mr Gul as president.
It warned it would defend the separation of state and religion, the legacy of the state's founder Mustafa Kemal Ataturk.
Our correspondent says the court is officially independent but had been under immense pressure to reach precisely this verdict. It is one that is likely to divide Turkey further, she says.
On Sunday, hundreds of thousands of people rallied in Istanbul in support of secularism.
Mr Erdogan appealed for national unity in a televised address to the nation on Monday.