British academic Matthew Hedges, who was sentenced to life in jail in the United Arab Emirates on spying charges, has been released from prison after receiving a pardon from the country’s president.

The 31-year-old student was arrested in May while leaving Dubai airport after conducting research for his PhD thesis. He was held for five months in solitary confinement and was denied access to a lawyer during his detention.

The case sparked a diplomatic row between the UAE and the UK, which denied that Mr Hedges was working as a spy. The foreign office was criticised for not intervening more quickly in the case, but the last week has seen an intense lobbying effort by the British government on his behalf.

Mr Hedges’s wife, Daniela Tejada, said the pardon was “the best news we could’ve 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,” she said.

Foreign secretary Jeremy Hunt, who was deeply involved in efforts to release Mr Hedges, called the pardon “fantastic news”.

“Although we didn’t agree with charges we are grateful to UAE government for resolving issue speedily. But also a bittersweet moment as we remember Nazanin and other innocent people detained in Iran,” he added, in reference to Nazanin Zaghari-Ratcliffe, a British-Iranian woman who has been detained in Iran for more than two years.

The pardon was issued by UAE president Khalifa bin Zayed al Nahyan on Sunday, and announced at a hastily convened press conference the next day. It came just minutes after Emirati officials stood by accusations that Mr Hedges was a spy.

“He was a part-time PhD researcher, a part-time businessman, but he was a 100-per cent a full-time secret service operative,” said Jaber al-Lamki, an official with the UAE’s National Media Council.

At the closed-door press conference, journalists were shown a video in which Mr Hedges allegedly acknowledged working for MI6.

“During the investigation, Mr Hedges confessed he was acting as an agent of a foreign intelligence service. He confirmed that he had collected sensitive and classified information about the UAE for that agency. The evidence, both documentary and electronic, is irrefutable,” Mr Lamki said.

Mr Hedges was sentenced last week in a move described as deeply disappointing by prime minister Theresa May. A spokesman for the prime minister said: “As we’ve been clear, we didn’t agree with the charges but we are grateful to the UAE government for resolving the issue.”

Both his family and the British government denied all the charges. Mr Hedges said he was in the country to research the impact of the Arab Spring on UAE foreign policy.

In the wake of the sentencing, the case was the focus of intense lobbying efforts by the British government.

Ms Tejada had pressed for his release and won assurances from Mr Hunt that the government was “standing up for” her husband, after she claimed it had initially put diplomatic relations with the UAE above his liberty.

During his detention, he was interrogated without a lawyer or consular access. A representative for the family said that his mental and physical health had “seriously deteriorated” during his time in solitary confinement.

Responding to news of the pardon, Amnesty International condemned UAE authorities for the handling of the case, and called for renewed pressure on the country to release other prisoners of conscience.

“Matthew should never have been jailed after such an unfair process, and he should never have been held in the miserable conditions of solitary confinement. A pardon doesn’t make up for this injustice,” said Kate Allen, Amnesty International UK’s director.

“Matthew’s ordeal is a reminder that the UAE is a deeply repressive country which ruthlessly suppresses free speech and peaceful criticism, and we should spare a thought for Emirati prisoners of conscience like Ahmed Mansoor or Mohammed al-Roken who aren’t getting a pardon today,” she added.