Fradrique de Menezes flew in from the Gabonese capital of Libreville accompanied by Nigerian President Olusegun Obasanjo after an agreement was reached to restore constitutional order to the impoverished west African islands.
"The accord is signed," said Congolese Foreign Minister Rodolphe Adada, as he returned to Sao Tome earlier on Wednesday from Libreville, where he had joined his Gabonese counterpart for talks with de Menezes.
Neither Adada nor Gabonese Foreign Minister Jean Ping, who also returned to Sao Tome on Wednesday, gave any further details of the deal.
But Fernando Pereira, leader of the self-styled military commission that carried out last week's coup, said an agreement had been struck that included an amnesty for all involved in the putsch.
Pereira made no further comments on the deal, but officials had earlier suggested the agreement being prepared would allow de Menezes to return to office.
President may return to office
On Tuesday, Pereira said he would not object to de Menezes returning to office as part of a settlement.
"It's not the president who is in question, nor the prime minister, nor anyone," he said. "It is the whole country, a nation that is in question."
The breakthrough follows three days of talks brokered by a 30-strong mediation team from several Portuguese-speaking and African countries as well as the United States.
It was not yet clear late on Wednesday what if any concessions the new accord included for the coup organisers.
Pereira recently described the ousting of the government as "an SOS to the international community" over rampant corruption and gruelling living conditions on the tiny islands, home to just 140,000 people.
Sao Tome and Principe is one of the poorest nations in Africa, but has offshore oilfields representing considerable potential oil wealth.
Many inhabitants have voiced hope that the removal of the government would result in an improvement in standards of living on the islands, where the average income currently stands at around $280 a year.