Troops in the West African country of Guinea-Bissau have freed the interim president and ex-prime minister seized in a coup.
Former PM Carlos Gomes Junior and interim President Raimundo Pereira are being flown to Ivory Coast, the BBC's John James reports.
The coup leaders have also agreed to a 12-month transition to civilian rule, as demanded by regional bloc Ecowas.
The army seized power during a presidential election on 12 April.
The soldiers claimed that Mr Gomes - who was considered the front-runner in the election - planned to reduce the size of the army.
Our correspondent, who is in Ivory Coast, says both freed men are due to meet Ivorian President Alassane Ouattara over the weekend, after more than two weeks of detention.
Earlier, Ecowas leaders agreed to send troops to Guinea-Bissau - and also Mali - following coups in both countries.
Ecowas warned Guinea-Bissau's coup leaders on Thursday that they faced targeted sanctions if they failed to agree to the deployment of troops within 72 hours.
The bloc said it expected both countries to hold presidential elections within the next 12 months.
No elected leader in nearly 40 years of independence has finished their time in office in the former Portuguese colony.
Guinea-Bissau has become a major staging post for gangs smuggling cocaine from Latin America to Europe.