Wyn Ellis
A very grateful Wyn Ellis out of an airport cell after four days.

British academic Wyn Ellis has been released after being held at the Bangkok's Suvarnabhumi Airport jail for four days after he was accused of being a national security threat over a plagiarism row going back as far as nine years.

The UK Foreign and Commonwealth Office said the situation is now resolved. Before his release, Ellis told a news agency that British Ambassador to Thailand, Mark Kent had telephoned him to say he was "trying to do something."

In a tweet, Ellis said that he was now "out of custody" and back at his home in Bangkok. The agricultural consultant has both British and Thai nationality and is married to a Thai woman, also an academic. He has lived in Thailand for 30 years, Reuters reported.

A Foreign Office spokesman had earlier told the Guardian before Ellis's release that it was providing consular assistance and that its embassy in Bangkok was in touch with the Thai authorities.

During his stay in the airport cell, he told the news agency: "They are looking after me well, the immigration officials have been apologetic. They call me 'professor'. But it's a little crowded and the lights are on 24-7/"

Ellis, who works for the United Nations in Thailand was put on the immigration blacklist in 2009 without his knowledge after he complained to the Chulalongkorn University that the then head of Thailand's National Innovation Agency Supachai Lorlowhakarn had submitted a doctorate dissertation that was largely plagiarised from a report he had written for Thailand's International Trade Centre.

Supachai, according to Reuters, was allowed to graduate despite the complaint. He went on to file nine lawsuits, including an accusation of defamation against Ellis.

The academic from Swansea has since won seven lawsuits and settled two others out of court. In 2012, Supachai was stripped of his doctorate but continued to be a director of the agency until early 2015, Reuters reported.

In the airport cell, immigration authorities showed Ellis a letter sent by Supachai in late 2009 describing Ellis as a "danger to Thai society" and accused him of forgery, stealing government documents and plagiarism, Ellis said.

Although the National Innovation Agency told the immigration department that it had revoked the letter from Supachai, it would take time to get Ellis off the blacklist.

Ellis said he had not had any problems travelling in the past but was detained when he tried to return to Bangkok using his British passport after he lost his Thai passport on a recent trip to Britain and Norway.

Initially, immigration officials had threatened to deport him back to Oslo where he had travelled from.

A very grateful Ellis thanked officials for removing him from the immigration blacklist.