East Timor's Premier Mari Alkatiri has resigned from his job in the wake of mounting pressure.
Mr Alkatiri has been under huge pressure in the last few weeks
President Xanana Gusmao accepted the decision with immediate effect.
Mr Alkatiri had been widely blamed for triggering recent violence in the capital, Dili, because of his decision to sack 600 soldiers.
While the ruling party, Fretilin, continued to back the prime minister, President Gusmao urged him to quit, as did thousands of street protesters.
"I declare I am ready to resign from my position as prime minister," Mr Alkatiri told reporters at a news conference in Dili on Monday.
"Assuming my own share of responsibility for the crisis affecting our country, I am determined not to contribute to any deepening of the crisis," he said.
A few hours afterwards, Mr Gusmao said he had accepted a resignation letter from Mr Alkatiri.
Thousands of people who had gathered in Dili to call for the prime minister to quit began to celebrate, banging drums and beeping car horns.
"I think this decision is acceptable for everyone," said one of the demonstrators, Augustino.
Australian Prime Minister John Howard also welcomed the news, saying it was "evidence we are moving to the resolution of the issue".
Ever since Mr Alkatiri made the decision to sack 600 disgruntled soldiers in March, his critics have urged him to resign.
Gun battles between the rebel soldiers and those loyal to the government then broke out, with machete-wielding youths forcing thousands to flee their homes in fear.
The unrest turned into East Timor's worst violence since it voted for independence from Indonesia in 1999, and led to the young nation asking foreign peacekeepers to come to its aid.
Mr Gusmao threatened to step down himself on Thursday
As well as blaming him for triggering the violence, Mr Alkatiri's opponents also allege that he formed a hit squad to kill his political rivals - a charge he firmly denies.
But despite the enormous pressure on him, from important donor countries and even from East Timor's popular president, the prime minister had - until Monday - adamantly refused to step down.
It is unclear what caused him to change his mind.
The resignation on Sunday of the popular foreign minister, Jose Ramos Horta, was undoubtedly a blow. But last week Mr Alkatiri had stood firm against a much more serious resignation threat from President Gusmao himself - a threat the president later rescinded.
There has been no indication so far of who will succeed Mr Alkatiri. Fretilin will select his replacement.
But according to the BBC's South East Asia correspondent, Jonathan Head, Mr Alkatiri's departure should make the task of stabilising East Timor easier, although the country will need significant international assistance for months, or even years, ahead.
A veteran of East Timor's independence movement, Mari Alkatiri spent the 24 years of Indonesian occupation in exile in Mozambique.
He is credited with skilfully negotiating with Australia over East Timor's rights to oilfields in the Timor Sea, but he is also viewed by many Timorese as a cold and arrogant politician.