Sri Lankan President Gotabaya Rajapaksa has announced he will step down after protesters stormed his official residence and set the prime minister's house on fire.
Neither the PM nor the president were in the buildings at the time.
Hundreds of thousands descended on the capital Colombo, calling for Mr Rajapaksa to resign after months of protests over economic mismanagement.
Mr Rajapaksa will step down on 13 July. PM Wickremesinghe has agreed to resign.
The speaker of parliament said the president decided to step down "to ensure a peaceful handover of power" and called on the public to "respect the law".
The announcement triggered an eruption of celebratory fireworks in the city.
Political leaders are due to hold further meetings to discuss a smooth transition of power. Sri Lanka's military has appealed to people to cooperate with security forces to maintain calm.
After Saturday's events, the United States appealed to the Sri Lankan leadership to act promptly to resolve the country's economic crisis.
One protester, Fiona Sirmana, who was demonstrating at the president's house, said it was time "to get rid of the president and the prime minister and to have a new era for Sri Lanka".
"I feel very, very sad that they didn't go earlier because had they gone earlier there wouldn't have been any destruction," she told Reuters.
Dozens of people were injured in Saturday's protests, and a spokesperson for Colombo's main hospital told AFP news agency that three people were being treated for gunshot wounds.
Sri Lanka is suffering rampant inflation and is struggling to import food, fuel and medicine amid the country's worst economic crisis in 70 years.
It has run out of foreign currency and has had to impose a ban on sales of petrol and diesel for private vehicles, leading to days-long queues for fuel.
The extraordinary events of Saturday appeared to be the culmination of months of mainly peaceful protests in Sri Lanka.
Huge crowds converged on the official residence of President Rajapaksa, chanting slogans and waving the national flag before breaking through the barricades and entering the property.
Footage online showed people roaming through the house and swimming in the president's pool, while others emptied out a chest of drawers, picked through the president's belongings and used his luxurious bathroom.
The contrast between the luxury of the palace and the months of hardship endured by the country's 22 million people was not lost on the protesters.
"When the whole country is under such strain people have come here to release that pressure. When you see the luxuries in this house it is obvious that they don't have time to work for the country," Chanuka Jayasuriya told Reuters.
Ousted in a day of fury
By Ethirajan Anbarasan, BBC News, Colombo
These are some extraordinary times for Sri Lanka.
After a day of fury and violence, the two senior leaders of the country have agreed to step down.
The news triggered jubilation at the main protest site in Colombo. Firecrackers were set off in many parts of the city.
I am at the Galle Face protest site - many protesters have started returning home, thousands are still present. Some have been singing and playing musical instruments, celebrating.
What a turnaround of events. A few days ago a photo of President Rajapaksa and Prime Minister Wickremesinghe smiling in parliament was widely shared on social media.
Many vented their anger, saying the two men appeared to be happy while millions were struggling to eat three meals a day. But a week is a long time in politics.
Mr Rajapaksa vacated his official residence on Friday as a safety precaution ahead of the planned protests, two defence ministry sources said, according to Reuters.
Although it is Mr Rajapaksa's official residence, he usually sleeps at a separate house nearby.
The BBC has been unable to confirm the president's whereabouts.
Protesters also set fire to Prime Minister Wickremesinghe's private home in an affluent neighbourhood of Colombo.
He said earlier that he was willing to resign to ensure the safety of civilians and to make way for an all-party government, but soon after his announcement videos started circulating of his house up in flames.
The prime minister lives with his family in the private home and uses his official residence for official business only.
Whether or not the president's and the prime minister's planned resignations will be enough to appease the protesters is not yet clear.
"Just two resignations alone will not satisfy the demands, the demand of a system change, but at least this is a start if the president and the prime minister depart," said Bhavani Fonseka, a prominent human rights lawyer in Colombo.
"There has to be a peaceful transition of power which is yet to be seen," she warned.
Sri Lanka: The basics
- Sri Lanka is an island nation off southern India: It won independence from British rule in 1948. Three ethnic groups - Sinhalese, Tamil and Muslim - make up 99% of the country's 22 million population.
- One family of brothers has dominated for years: Mahinda Rajapaksa became a hero among the majority Sinhalese in 2009 when his government defeated Tamil separatist rebels after years of bitter and bloody civil war. His brother Gotabaya, who was defence secretary at the time, is the current president but says he is standing down.
- Now an economic crisis has led to fury on the streets: Soaring inflation has meant some foods, medication and fuel are in short supply, there are rolling blackouts and ordinary people have taken to the streets in anger with many blaming the Rajapaksa family and their government for the situation.