COLOMBO, SRI LANKA -- Sri Lanka's prime minister resigned following weeks of protests demanding that he and his brother, the country's president, step down for dragging the nation into its worst economic crisis in decades.

Prime Minister Mahinda Rajapaksa said on Twitter that he submitted his resignation to President Gotabaya Rajapaksa, a move that followed a violent attack by government supporters on the protesters, prompting authorities to deploy armed troops in the capital, Colombo.

Four people, including a ruling party lawmaker, died in Monday's violence, police spokesman Nihal Thalduwa told the Associated Press. President Rajapaksa imposed a countrywide curfew Monday evening lasting until Wednesday morning.

For more than a month, protests have spread across the country, drawing people across ethnicities, religions and class. For the first time middle-class Sri Lankans also took to the streets in large numbers, marking a dramatic revolt by many former Rajapaksa supporters, some of whom have spent weeks protesting outside the president鈥檚 office.

The protests underscored a dramatic fall from favour of the Rajapaksas, Sri Lanka鈥檚 most powerful political dynasty for decades. The brothers were once hailed as heroes by many of the island鈥檚 Buddhist-Sinhalese majority for ending the country鈥檚 30-year civil war, and despite accusations of war atrocities, were firmly entrenched at the top of Sri Lankan politics until now.

The prime minister鈥檚 resignation comes as the country鈥檚 economy has swiftly unraveled in recent weeks. Imports of everything from milk to fuel have plunged, spawning dire food shortages and rolling power cuts. People have been forced to stand in lines for hours to buy essentials. Doctors have warned of crippling shortages of life-saving drugs in hospitals, and the government has suspended payments on US$7 billion in foreign debt due this year alone.

President Gotabaya Rajapaksa initially blamed Sri Lanka's economic woes on global factors like the pandemic battering its tourism industry and the Russia-Ukraine conflict pushing up global oil prices. But both he and his brother have since admitted to mistakes that exacerbated the crisis, including conceding they should have sought an International Monetary Fund bailout sooner.

Sri Lanka has been holding talks with the IMF to set up a rescue plan but its progress depends on negotiations on debt restructuring with creditors. Any long-term plan would take at least six months to get underway.

Sri Lanka was in financial trouble even before the Ukraine war drove up food and oil prices.

The Sri Lankan government has been running big budget deficits after cutting taxes in 2019 and struggling to collect taxes during the COVID-19 pandemic. It also has piled up massive foreign debt 鈥 much of it owed to China 鈥 and has scant foreign exchange reserves to pay for imports and to defend its embattled currency, the rupee.

Sri Lanka is at the top of a list compiled by Liliana Rojas-Suarez of the Center for Global Development that ranks the countries most exposed to financial shocks. Those most vulnerable rely on commodity imports and have low foreign exchange reserves compared to what they owe other countries.

Monday's violence triggered widespread anger, with people singling out Rajapaksa supporters and attacking them in many parts of the country.

Ruling party lawmaker Amarakeerthi Athukorale and his bodyguard were killed in Nittambuwa, some 30 kilometres north of Colombo after the car they were travelling in was intercepted by an angry crowd, the police spokesman said.

Athukorale or his bodyguard had fired gunshots at the protesters, who chased them and trapped them inside a building where their badly beaten bodies were recovered by police several hours later, the spokesman said.

Three people were hospitalized with gunshot wounds from the shots fired from the lawmaker's vehicle, he said.

Separately, in the Rajapaksas' hometown of Weeraketiya, a crowd that tried to set fire to a local politician's home was fired upon, killing two protesters, he said.

Protesters tried several times to break into the prime minister's official residence Monday night forcing police to fire tear gas. Homes of government ministers and politicians supporting the Rajapaksas were also attacked and some set on fire. The memorial for the brothers' parents was vandalized.

Jayadeva Uyangoda, a political scientist in Colombo, said the prime minister's resignation marked a new chapter in the country鈥檚 political crisis. 鈥淭he prime minister had to resign in disgrace after his supporters unleashed such violence,鈥 he said.

He added that it would be difficult for President Gotabaya Rajapaksa to maintain credibility after Monday's violence.

But the president has so far refused to resign and Parliament must go through a difficult process if it attempts to oust him. The resignation of the prime minister meant the entire Cabinet was dissolved.

The U.S. condemned the violence while also expressing concern about the emergency declaration, which it said can be used to curb dissent.

鈥淲e urge the government to work quickly to identify and implement solutions to achieve long-term economic stability and address the Sri Lankan people鈥檚 discontent over the worsening economic conditions including power, food and medicine shortages as well," State Department spokesperson Ned Price told reporters in Washington.

Earlier on Monday, the prime minister's supporters attacked protesters who had been demonstrating outside the prime minister鈥檚 official residence for weeks, hitting them with wooden and iron poles. They then marched to the president鈥檚 office, where they attacked protesters there and set their camps on fire.

Police fired tear gas and a water cannon, but not forcefully enough to control the mob. The attack occurred despite a state of emergency declared by the president Friday that gave him wide powers for riot control.

Hundreds of armed soldiers were deployed in the capital, as the protesters accused police of not preventing the attack, despite using tear gas and water cannons on protesters on Friday.

鈥淧olice did not protect us, therefore we have taken it into our own hands,鈥 said Druvi Jinasena, who was helping block roads to protect the protest site.

An official at the main hospital in Colombo said 173 people were treated, most for minor injuries, though 15 were seriously injured. The official spoke on condition of anonymity because she was not authorized to speak to the media.

The country鈥檚 foreign reserves have plummeted below $50 million and it owes nearly $25 billion in foreign debt for payment by 2026. Its total foreign debt is $51 billion.

Meanwhile, popular anger at the Rajapaksa clan has only grown, ramping up pressure on President Gotabaya Rajapaksa to quit too.

鈥淭here has been sustained pressure for the last several weeks for the president to resign but he hasn鈥檛 paid much attention to that," said Bhavani Fonseka, a senior researcher at the Colombo-based Center for Policy Alternatives.

鈥淧eople are furious 鈥 and that anger is not going away anytime soon.鈥

Pathi reported from New Delhi. AP Economics Writer Paul Wiseman in Washington contributed to this report.