COLOMBO, July 11 (Reuters) - Sri Lanka's parliament will elect a new president on July 20, its speaker said on Monday, after protesters stormed the residences of the current president and prime minister, who have both offered to quit amid an economic meltdown.

President Gotabaya Rajapaksa, who had overseen a ruthless crushing of the Tamil Tigers insurgents as defence secretary, is set to resign on Wednesday. His brothers and nephew earlier quit as ministers as Sri Lanka began running out of fuel, food and other essentials in the worst crisis since independence from Britain in 1948.

Parliament will reconvene on Friday and will vote to elect a new president five days later, Speaker Mahinda Yapa Abeywardena said in a statement.

"During the party leaders' meeting held today it was agreed that this was essential to ensure a new all-party government is in place in accordance with the Constitution," the statement added.

"The ruling party has said the prime minister and the Cabinet are ready to resign to appoint an all-party government".

Prime Minister Ranil Wickremesinghe, whose private home was set alight by protesters, has said he will step down. His office said Rajapaksa had confirmed his resignation plans to the prime minister, adding that the cabinet would resign once a deal was reached to form an all-party government.

The political instability could damage negotiations with the International Monetary Fund (IMF) for a rescue package, the central bank governor told Reuters.

Governor P. Nandalal Weerasinghe signalled he would stay on in the job although he had said in May he could resign if there was no political stability in the island nation of 22 million.

Leaders of the protest movement have said crowds will occupy the residences of the president and prime minister in Colombo until they finally quit office. Over the weekend at the president's house, protesters jumped into the swimming pool, lounged on a four-poster bed, jostled for turns on a treadmill and tried out the sofas.

Colombo was calm on Monday as hundreds of people strolled into the president's secretariat and residence and toured the colonial-era buildings. Police made no attempt to intervene.

"We are not going anywhere till this president leaves and we have a government that is acceptable to the people," said Jude Hansana, 31, who has been at a protest site outside the residence since early April.

Another protester, Dushantha Gunasinghe, said he had travelled 130 km (80 miles) to Colombo, walking part of the way because of a fuel crunch.

"I'm so exhausted I can barely speak," said the 28-year-old as he sat outside the president's office. "I came alone all this way because I believe we need to see this through. This government needs to go home and we need better leaders."

Police said they had received 17.8 million rupees (about $50,000) found by a group of protesters at the president's residence on Saturday. A video of the youngsters counting out the cash went viral on social media.

U.N. Secretary-General Antonio Guterres called for a smooth transition of government and "sustainable solutions" to the economic crisis.