Somalia's transitional government, which is battling Islamic fighters, only holds a small area of Mogadishu, the capital, with the help of 5,300 African Union peacekeepers.
"We should not busy ourselves with our differences while an enemy determined to harm the population is in the country,'' Ahmed said on Monday.
Parliamentary business has been paralysed this year, with many legislators living in Kenya, Europe and North America because of security fears in the war-riven country.
Sunday's parliamentary gathering was the first such meeting this year.
The chamber has been split by a bitter feud over the duration of Madobe's term in office and his competence.
There was speculation that Madobe had been offered a ministerial post in a new government in return for his resignation.
"I do not think the president's announcement is to increase confusion in the system," Abdirahman Moalim Badiyow, a history professor at Mogadishu University, said.
"The resignation of the speaker and the president's decision seems to be a gentlemen's agreement paving the way for a new start.
"And that new beginning will depend on the incoming speaker and prime minister."
Ahmed's critics say he has failed to unite the country's warring factions and has been unable to establish a greater degree of central power that many had hoped at his election in January 2009.
Somalia has been mired in violence and has lacked effective central government since 1991.
Islamic fighters, such as al-Shabab, have fought a three-year war against the UN-backed interim government.