Updated

Sri Lankan President Gotabaya Rajapaksa fled the country early on Wednesday, just days after thousands of protesters stormed his residence over the nation's crippling economic crisis.

Rajapaksa and Prime Minister Ranil Wickremesinghe had both agreed to resign, with the president's resignation effective on Wednesday. Wickremesinghe said he will step down once a new government is in place, but demonstrators are demanding he resign immediately.

Protesters stormed the prime minster’s office following Rajapaksa's departure from Sri Lanka, and parts of the country have declared a national state of emergency.

Groups could be seen scaling the wall and entering the office as the crowds roared in support, cheering them on and waving the Sri Lankan flag. Police used tear gas to try to disperse the crowd but failed and more and more marched down the lane and towards the office.

SRI LANKAN PRESIDENT, PRIME MINISTER TO RESIGN AFTER PROTESTERS STORM RESIDENCES, SET FIRE

Sri Lankan President Gotabaya Rajapaksa

FILKE- Sri Lankan President Gotabaya Rajapaksa sings the national anthem of Sri Lanka during the country's Independence Day celebration in Colombo, Sri Lanka, Feb. 4, 2022. The president of Sri Lanka fled the country early Wednesday, July 13, 2022, days after protesters stormed his home and office and the official residence of his prime minister amid a three-month economic crisis that triggered severe shortages of food and fuel. (AP Photo/Eranga Jayawardena)

On Wednesday morning, Sri Lankans continued to stream into the presidential palace. A growing line of people waited to enter the residence, many of whom had traveled from outside Colombo on public transport. Protestors said they would stay in the official buildings until the top leaders are gone.

The president, his wife and two bodyguards departed the country on a Sri Lankan Air Force plane headed for the Maldives, according to an immigration official. Rajapaksa left just hours before he was to leave his post. The president would later appoint the prime minister as the acting president, the speaker of the parliament said.

This comes after months of demonstrations against Sri Lankan officials as the South Asian country grapples with severe food and fuel shortages and skyrocketing inflation.

Protesters, in recent days, had broken into Rajapaksa's home, occupying beds and swimming in a pool. They had also targeted the prime minister's private residence and set it on fire.

Some demonstrators waved the Sri Lankan flag as chants broke out against the president and prime minister.

The president and his family are accused by protesters of siphoning money from government coffers for years, although the family has denied the allegations. And the Rajapaksa administration is blamed for contributing to the country’s economic collapse through its policies. Rajapaksa has acknowledged that some of his policies have contributed to the crisis.

"I am not happy he has fled. He should be in jail," one protester occupying the president’s office said, adding that Rajapaksa "ruined this country and stole our money. We will not stop until we have a new president and prime minister."

SRI LANKA PRESIDENT BLOCKED BY AIRPORT STAFF DURING ATTEMPT TO FLEE COUNTRY AFTER PROTESTERS BREAK INTO HOME

Sri Lanka protests inside the home of president Gotabaya Rajapaksa

Protesters sit on chairs inside the official residence of president Gotabaya Rajapaksa after it was stormed by anti-government protesters in Colombo, Sri Lanka, Wednesday, July 13, 2022. (AP Photo/Rafiq Maqbool)

The air force said in a statement that an aircraft was provided for the president and his wife for their flight to the Maldives. The flight was approved by the defense ministry. All immigration and customs laws were adhered to, the statement said.

Sri Lankan lawmakers agreed to elect a new president next week, although they struggled Tuesday to decide on the makeup of a new government to help elevate the impoverished country out of economic and political collapse. 

The lawmakers also have yet to choose someone to take over as prime minister and fill the Cabinet.

Rajapaksa's replacement would serve as president for the remainder of his term, which ends in 2024. The new leader could potentially select a new prime minister, who Parliament would have to approve.

ECONOMIC PROTESTS RAGE WORLDWIDE AS CHALLENGES FROM INFLATION, UKRAINE WAR, CORONAVIRUS MOUNT

A protester takes a picture at the home of the president of Sri Lanka

A man takes selfie at the swimming pool of the official residence of president Gotabaya Rajapaksa three days after it was stormed by anti-government protesters in Colombo, Sri Lanka, Tuesday, July 12, 2022. (AP Photo/Rafiq Maqbool)

The country of about 22 million people is undergoing a severe foreign exchange shortage, which has limited essential imports of fuel, food and medicine. The shortage has pushed the island into its worst financial situation in 70 years.

Sri Lanka has not been receiving fuel shipments in recent weeks, forcing school closures and limiting petrol and diesel for essential services. Residents are skipping meals to line up for hours for scarce fuel.

CLICK HERE TO GET THE FOX NEWS APP

And the nation's inflation levels are soaring. Sri Lanka's inflation reached 54.6% in June.

The nation's political turmoil could impact its hopes of receiving a bailout from the International Monetary Fund. The government has to submit a plan to the IMF in August on debt sustainability before a deal can be reached.

The Associated Press contributed to this report.