British academic Matthew Hedges has been freed from jail after being pardoned from his life sentence for spying in the United Arab Emirates.
Officials there said the PhD student had admitted to being in MI6, a claim his family has denied, but released him as part of the country's National Day pardons.
The 31-year-old, originally from Exeter, was arrested at Dubai Airport as he tried to leave the country on 5 May.
Mr Hedges' wife Daniela Tejada said news of the pardon brought her family's "nightmare" to an end, and British Foreign Secretary Jeremy Hunt described it as "fantastic".
At a news conference in Abu Dhabi, officials showed a video of Mr Hedges describing himself as a captain in MI6 during what appeared to be a court hearing.
An official told reporters that Mr Hedges was "100% a full-time secret service operative" who was in the country "to steal the UAE's sensitive security national secrets for his paymasters".
He said Mr Hedges’ pardon came in response to a letter from his family appealing for clemency and due to the historical close ties between the UK and UAE.
"His Highness has decided to include Mr Matthew Hedges among the 785 prisoners released," he said.
"Mr Hedges will be permitted to leave the country once all the formalities are complete."
The UAE confirmed Mr Hedges' release a short time later.
In a statement, Ms Tejada, said: "The presidential pardon for Matt is the best news we could have received.
"Our six-plus months of nightmare are finally over and to say we are elated is an understatement.
"That he is returning home to me and the rest of his family is much more than I was ever expecting to happen this week. I thank you all for your support."
She credited media coverage, support from British diplomats, Mr Hunt, academics and members of the public across the world for helping to her husband's cause.
She continued to reject the accusation that he was a spy, telling BBC Radio 4's Today programme: "In my heart I know that he isn't."
Mr Hunt said the UAE had made a "very important gesture" in pardoning Mr Hedges but described it as a "bittersweet moment" given that Briton Nazanin Zaghari-Ratcliffe remains detained in Iran, also accused of spying.
Speaking on the same programme: "In a way it's a bittersweet moment as in Iran, another country in the region, we have Nazanin Zaghari-Ratcliffe, an innocent woman who is still in prison for nearly three years now.
"Indeed, there are other British citizens and other citizens from other countries also wrongly imprisoned in Iran also.
"So, you know the wonderful news about Matthew is also making us remember there are other people who are in a terrible state right now and we must never forget them either."
UAE minister of state for foreign affairs Anwar Gargash said the pardon would allow the two countries to "return our focus to the underlying fundamental strength of the UAE-UK bilateral relationship", the WAM Emirates news agency reported.
Dr Gargash said: "His Highness the President's gracious clemency in the customary National Day pardons allows us to return our focus to the underlying fundamental strength of the UAE-UK bilateral relationship and its importance to the international community.
"It was always a UAE hope that this matter would be resolved through the common channels of our longstanding partnership.
"This was a straightforward matter that became unnecessarily complex despite the UAE's best efforts."
Professor Stuart Corbridge, vice-chancellor of Durham University said: "We are absolutely delighted to learn the news of Matt's impending release.
"It is paramount that he is now allowed to return home to Daniela and his family as quickly and safely as possible.
"We will continue to offer Matt's family our full support in the aftermath of this traumatic ordeal and we will be thrilled to welcome him back to the Durham University community."