British teacher David Bolam has been released after being held hostage by militants in Libya since May.
The Foreign Office said Mr Bolam, who taught at the now-closed International School Benghazi, was “safe and well” and had been reunited with his family.
Mr Bolam’s MP in Craven Arms in Shropshire said he was “delighted” that the 63-year-old was back home safely.
It is thought the teacher’s release was secured by local political factions and that money changed hands.
Mr Bolam’s kidnapping had not been reported at the request of the Foreign Office and his family.
BBC world affairs correspondent Caroline Hawley said she understood demands for a ransom had been made to the school and that money was handed over to secure his release.
She said it was “unclear” how much money was paid and who paid it, but the Foreign Office was not involved in the negotiations.
Mr Bolam, who flew back to the UK on Thursday night, had been working in Libya for seven years.
He had appeared in a video posted online on 28 August.
Wearing a white T-shirt and sitting in a concrete room, he appealed to UK Prime Minister David Cameron to secure his release.
He said he was in good health and had been held “a very long time”.
There had been fears Mr Bolam faced the same fate as British hostages held by Islamic State (IS) militants operating in Syria and Iraq, BBC security correspondent Gordon Corera said.
In recent weeks, IS has released videos showing the apparent beheading of two US journalists, James Foley and Steven Sotloff, and British aid workers David Haines and Alan Henning.
However, little is known about the group which held Mr Bolam and what their demands may have been, our security correspondent added.
Charlie Cooper of counter-extremism think tank the Quilliam Foundation said the difference between the treatment of Mr Bolam and Mr Henning was “indicative of the huge difference between other jihadist groups and Islamic State”.
He told BBC Breakfast: “Islamic State is profoundly more extreme in its outlook and in its ideological motivations.”
Caroline Hawley says Benghazi – where the uprising against Muammar al-Gaddafi began – is now a chaotic place “where Islamist militias and criminal gangs abound”.
Philip Dunne MP, whose constituency includes Craven Arms, said he shared the relief of Mr Bolam’s family and friends at his release.
“I have been in touch with his wife during his ordeal over recent months and know how relieved she is that he has returned safely home,” Mr Dunne said.
“David is a dedicated English teacher who had returned to Benghazi to help rebuild the international school of which he was a director, after he had been evacuated during the Arab Spring.
“He was trying to help young people in Libya gain a good education.”
A Foreign Office spokeswoman said: “We are glad that David Bolam is safe and well after his ordeal, and that he has been reunited with his family.
“We have been supporting his family since he was taken.”
The British ambassador to Libya, Michael Aron, also tweeted his delight.
Ged O’Connor Challis taught at the international school along with his wife Siobhan until December 2013, so had left by the time Mr Bolam was abducted in May.
He said he had spoken to Mr Bolam on the phone on the morning he was kidnapped, and school staff later said “one of the local militias had grabbed David as he went out shopping”.
Mr O’Connor Challis, who now lives in Manchester, said Mr Bolam stayed in Libya when other staff left because he “believed in what he was doing”.
“He is single-minded and stubborn,” he said.
“He is a very bright person. He is an English teacher – one of the best I have ever met.”
Teachers had wanted to stay at the school, Mr O’Connor Challis said, but a “massive gunfight” in November 2013 and the fatal shooting of teacher Ronnie Smith in December were part of growing violence which convinced many to leave.