Mr Rajoelina's takeover is widely seen as a coup d'etat
A breakthrough has been made in talks to resolve a political crisis in Madagascar, a UN official has said.
Special envoy Tiebile Drame told the BBC various political parties had agreed to an inclusive transitional government and a reconciliation body.
He also said both ousted President Marc Ravalomanana and Andry Rajoelina, who took power with the help of the army in March, could stand in upcoming polls.
In recent months more than 100 people have died in violence in Madagascar.
The army-backed takeover by Mr Rajoelina has been widely condemned as a coup d'etat.
Mr Ravalomanana now lives in exile in South Africa.
Mr Drame told the BBC that Madagascar's political parties had agreed to set up a South African-style truth and reconciliation commission in an attempt to heal some of the wounds caused by the numerous political crises the country had suffered.
Perhaps the most controversial agreement is that all former and current leaders, including Mr Ravalomana and Mr Rajoelina, would be eligible to stand in the upcoming presidential elections, the BBC's Jonny Hogg in Antananarivo says.
Mr Drame described this decision as "unfortunate".
He adds that the international community has suggested that neither of the two leaders should take part in the polls, saying this could destabilise the Indian Ocean island further.