The Gambia's long-term leader Yahya Jammeh says he will step down, after refusing to accept defeat in elections.
In an announcement on state TV, he said it was "not necessary that a single drop of blood be shed".
The statement followed hours of talks between Mr Jammeh and West African mediators. He gave no details of what deal might have been struck.
Mr Jammeh has led the country for 22 years but was defeated in December's election by Adama Barrow.
Troops from several West African nations, including Senegal, have been deployed in The Gambia, threatening to drive Mr Jammeh out of office if he did not agree to go.
Mr Barrow has been in neighbouring Senegal for days and was inaugurated as president in the Gambian embassy there on Thursday.
In an interview with the BBC, Mr Barrow pledged to establish a truth and reconciliation commission to investigate alleged human rights abuses in The Gambia under Mr Jammeh.
"In that commission I think there will be recommendations, we will act according to those recommendations but we have got to know the truth first," he said.
He added that he would return to the country "sooner rather than later".
Mr Jammeh's decision to quit came after talks with the presidents of Guinea and Mauritania.
"I have decided today in good conscience to relinquish the mantle of leadership of this great nation with infinite gratitude to all Gambians," he said.
"I promise before Allah and the entire nation that all the issues we currently face will be resolved peacefully."
Mauritanian President Mohamed Ould Abdel Aziz was quoted by his country's state news agency as saying that a deal had been struck and that Mr Jammeh would leave for another African country "with guarantees for his family, those close to him and himself".
He gave no further details.
Mr Jammeh was given an ultimatum to leave office or be forced out by UN-backed troops, which expired at 16:00 GMT on Friday.
The deadline was set by the Economic Community of West African States (Ecowas), a regional grouping backed by the United Nations.
The first signs of a breakthrough came on Friday when a senior aide to the new president told the BBC's Umaru Fofana that Mr Jammeh had agreed to step down.
Mr Jammeh had at first accepted defeat in the election but then reversed his position and said he would not step down.
He declared a 90-day state of emergency, blaming irregularities in the electoral process.
The electoral commission accepted that some of its early results had contained errors but said they would not have affected Mr Barrow's win.
Mr Jammeh had vowed to stay in office until new elections were held.