An ailing Muslim cleric, Mr Abdurrahman Wahid, yesterday won Indonesia's first contested presidential election, beating the favourite of the masses, Ms Megawati Sukarnoputri, whose supporters immediately went on the rampage.
Thousands clashed with security police outside the parliament when a party car was blown up by a bomb, and there were reports of protests and destruction in at least two other cities.
For Ms Megawati it was snatching defeat from the jaws of victory. Several of her potential allies have complained of her failure to try seriously to form a political union with them.
In the end the People's Consultative Assembly chose the shrewd Mr Wahid, the only man to establish anything resembling a power base during the 32 years former President Suharto was in power without actually siding with the now disgraced autocrat.
"This is not only Gus Dur's victory," the assembly speaker, Mr Amien Rais, said, referring to Mr Wahid's popular nickname.
"This is the victory of the Indonesian people. I hope the reform will go on well through Gus Dur's election. I believe our friends from any ethnic group, religion can open a new chapter," said Mr Rais, a reformist who had formed an alliance of mostly Muslim parties to back Mr Wahid.
His election brought an immediate welcome from the US and Indonesia's Asian neighbours, but there were clear concerns that the country's uneasy transfer to democracy was far from over.
"We have to see how the political process plays out in Indonesia itself . . . the next 24 hours are quite crucial," the US Assistant Secretary of State, Mr Stanley Roth, said.
A key factor is the election of the vice-president by the assembly today.
In an interview earlier this week, Mr Wahid said he would take as his number two the chairman of the former ruling Golkar party, Mr Akbar Tandjung.
It was Golkar which switched at the last moment behind Mr Wahid after the party's own candidate, the unpopular President B.J. Habibie, was forced to withdraw from the race after the assembly refused to accept his defence of his turbulent 17-month rule.
The politically influential military also threw its hat into the ring, saying the military commander, Gen Wiranto, was prepared to be vice president if all the parties asked him.
Ms Megawati's aides declined to say whether she might seek consolation as the number two.
Clearly shocked by her loss, Ms Megawati kept tight-lipped when the national anthem was sung after the vote result, leaving the assembly hall without a word. Her supporters were more vocal.
Thousands of protesters clashed with security police outside parliament when a party car was blown up by a bomb.
Riot police beat them back with batons and tear gas and at least four people were injured. Unconfirmed reports said one person had died.
Immediately before the voting, a bomb exploded in central Jakarta where hundreds of Ms Megawati's supporters had staged a rally.
In the central Java city of Solo, witnesses saw thick smoke pouring from the city hall and hundreds of protesters on the streets dressed in the colours of Ms Megawati's party. Thousands more gathered in the major north Sumatran city of Medan to protest against her defeat.
"Mega[wati] should become president . . . or revolution," shouted one protester.
Surging prices in Jakarta's financial markets after Mr Habibie withdrew in the morning quickly reversed after Mr Wahid's victory and news of the violence.
At one stage share prices jumped 10 per cent and the rupiah currency hit a three month high, but by the end of the day both were back more or less where they had started.
Paul Tait reports from Darwin:
The East Timorese separatist leader, Mr Xanana Gusmao, yesterday applauded the vote in the Indonesian assembly earlier in the day accepting the independence of East Timor.
Mr Gusmao joined the international community in welcoming the ratification by the People's Consultative Assembly of the territory's vote for independence on August 30th.
"My people are very happy . . . it is the moment that we waited for, for so long," said Mr Gusmao.