Gotabaya Rajapaksa has resigned as president of Sri Lanka after fleeing to Singapore in the face of mass protests at home over his rule.

He is believed to have wanted to leave Sri Lanka before stepping down in order to avoid the possibility of arrest under a new administration.

The cost of food, fuel and other basic supplies has soared for Sri Lankans.

In the capital Colombo, delighted demonstrators greeted news of the president’s departure with dancing.

“We are beyond happy but also beyond relieved so we can take a break and go back to our lives,” Viraga Perera told the BBC.

“At this stage we are so exhausted because of all the flip-flopping, that we consider this moment substantial enough as a victory.”

Mr Rajapaksa arrived in Singapore earlier on Thursday after first flying to the Maldives on Tuesday night. Reports say he is accompanied by his wife and two bodyguards.

Singapore’s foreign ministry said Mr Rajapaksa had not asked for asylum or been granted asylum. “Singapore generally does not grant requests for asylum,” it added.

The acting president, Ranil Wickremesinghe, does not formally become interim president until he is sworn in.

After that, Mr Wickremesinghe – who was appointed acting president by President Rajapaksa after the latter fled – has 30 days for parliament to endorse him. If they do not, MPs need to hold a vote for a new president.

The resignation letter was sent by email to the speaker of parliament, who said he would complete legal processes and announce it officially on Friday.

It has left some confused as to where they stand.

“Earlier they fooled us [in saying] that he would go. It’s the same thing happening now, they have received the resignation letter but the speaker says they have to legalise it. I don’t know what there is to legalise. So it’s really crazy,” said Suzette Fernando, who was among the crowds celebrating.

However, the crowds appeared smaller than before: Mr Wickremesinghe on Thursday imposed a curfew for a second day to quell protests.

The streets of Colombo were calmer as anti-government demonstrators began leaving some of the official buildings they had occupied.

“We are peacefully withdrawing from the presidential palace, the presidential secretariat and the prime minister’s office with immediate effect, but will continue our struggle,” said a spokeswoman for the protesters.

One person died and 84 others were injured during Wednesday’s protests, which took place at key landmarks around the capital, Colombo, including the prime minister’s office.

A resignation that took days to come

The resignation letter Sri Lankans have been waiting for since people power toppled Gotabaya Rajapaksa has finally arrived.

The letter does several things. Firstly, Prime Minister Ranil Wickremesinghe’s position as acting president is legitimised. Under Sri Lanka’s constitution the prime minister becomes caretaker leader in the event of the president resigning.

Secondly, it clears obstacles blocking the holding of an election in parliament for a new president. MPs had been due to meet on 15 July and start this process, with a vote promised a week later. That was delayed by the lack of a resignation letter but now it has arrived the Speaker will be able to reconvene parliament.

The two main candidates so far are likely to be Mr Wickremesinghe and opposition leader Sajith Premadasa. But given the governing party has a majority, its MPs are likely to back Mr Wickremesinghe – who has close links with the Rajapaksas. Whether Sri Lanka’s public would accept this is another matter. The prime minister’s resignation, along with that of Mr Rajapaksa, has been a key demand of protesters.

Thirdly, the resignation means Gotabaya Rajapaksa no longer has legal immunity as a head of state and his position is now more precarious as he tries to find a safe country to shelter in.

Major demonstrations since April over the country’s economic crisis escalated after protesters broke into the presidential palace on Saturday and set fire to the prime minister’s private home.

On Wednesday, police fired tear gas at protesters attempting to break down the gates of the prime minister’s office in Colombo, before finally forcing their way in. They later headed for parliament but did not get in.

By Thursday, protesters had handed back the president’s official residence to the authorities when the BBC visited. There were no protesters at parliament on Thursday afternoon, a BBC correspondent confirmed.

“We captured this building to show people power. We give it back the way we captured it and leave. We will come back in the next minute if needed,” Danish Ali, a protester at the prime minister’s office, told BBC Tamil.

Sri Lanka: The basics