Gambia's Yahya Jammeh agreed "in principle" to hand over power to President Adama Barrow on Friday, Mauritanian and Guinean sources said, but differences remained before a full deal could be reached.
Mauritania's President Mohamed Ould Abdel Aziz and Guinea's Alpha Conde held several hours of talks with Jammeh in which they agreed he should step aside but not how and where he would live out his exile.
Troops from five African nations were stationed on the tiny nation's borders in the event the last-ditch talks fell through, as it was confirmed Conde would stay into Saturday to iron out remaining disagreements.
Jammeh has refused to recognise his defeat in presidential elections last month, and would be offered asylum in the country of his choice, Conde advisor Kiridi Bangoura said earlier in the day.
"Jammeh has accepted he will leave power. The discussions revolve around where he will live in exile and the conditions around that," a Mauritanian source close to the delegation in Banjul told AFP.
A highly-placed Guinean source said the country of exile had to be far enough away to stop Jammeh interfering in his country's affairs.
The three men met at Jammeh's seat of power, State House, and halted to observe Friday prayers together at a nearby mosque.
The Guinean source mentioned Equatorial Guinea as a possible option, while diplomats discussed the possibility of Morocco.
Jammeh has rejected President Adama Barrow's December 1 election win, despite huge pressure from regional powers and the UN, sparking a major crisis and sending Gambians and tourists -- vital for the tiny country's economy -- fleeing.
Isatou Touray, a top official in Barrow's coalition told AFP there was "no deal yet" but added: "I think he has to go, because he is compelled."
- 'An ultimatum' -
Barrow, who was sworn in at The Gambia's embassy in Dakar on Thursday, remained in Senegal awaiting the outcome of the talks, with hopes of taking over from Jammeh as soon as his safety could be guaranteed.
A Banjul-based diplomatic source told AFP the final deal would be "a joint statement between Barrow and Jammeh," but cautioned the mercurial strongman could "quite easily" change his mind.
That source spoke of a three-day grace period for Jammeh with foreign troops on standby until he definitively quits the country.
Barrow hailed a "victory of the Gambian nation" and demanded loyalty from his armed forces at his inauguration on Thursday.
An imminent military operation, dubbed operation "Restore Democracy", was suspended late Thursday to allow the final push to convince Jammeh to leave after 22 years at the helm of the former British colony.
- Shifting loyalties -
As white flags reportedly flew from Gambian army posts in the countryside, sources suggested there was a gradual acceptance of Barrow, even among units known for loyalty to Jammeh.
A diplomatic source said a faction had "switched sides" among the elite Republican Guards who assure Jammeh's personal protection, following meetings among themselves at their Bakau barracks close to Banjul.
Gambia's army chief Ousman Badjie said foreign troops would be welcomed "with a cup of tea" rather than gunfire if they intervene to ensure Jammeh stands down.
"Why should we fight?", said Badjie, a former Jammeh loyalist.
"This is a political misunderstanding. There is no military solution to a political problem, let me tell you. We are not fools. I love my soldiers. I love the Gambian people. Nobody is going to be hurt here."
Soldiers were told by Barrow in his inauguration speech they would be considered rebel elements if they remained armed on the streets.
- Cabinet dissolved -
Police chief Yankuba Sonko and customs boss Momat Cham also swore allegiance to Barrow, a government source who asked not to be identified told AFP.
After a string of ministerial resignations this week, Jammeh however appeared determined to stand his ground to the last, announcing he was dissolving the government and taking over.
"The President of the Republic of The Gambia Sheikh Professor Dr Alhaji Yahya Jammeh Babili Mansa has dissolved his cabinet today," a statement said. "The office of the President oversees all ministries.
The uncertainty continued to push Gambians to flee the country and the United Nations refugee agency said around 45,000 had left so far, more than 75 percent of them children, mostly accompanied by women.
"They are staying with family members, host families or in hotels. Some families are hosting up to 40 to 50 people and will soon need support as they may quickly run out of resources," a United Nations High Commissioner for Refugees (UNHCR) report said.