A British resident, detained at Guantánamo Bay as an alleged terrorist for four years, is to be released and flown back to Britain, the foreign secretary, Margaret Beckett, announced yesterday.

Bisher al-Rawi, an Iraqi citizen, had lived in Britain for 19 years when he was arrested in the Gambia in 2002 while setting up a peanut processing factory with his brother. He was questioned and handed over to the CIA after information was passed to the US and Gambian authorities by Britain's security services.

But it is now known that Mr Rawi from Kingston, south-west London, had acted as a go-between for MI5 and the London-based preacher Abu Qatada, who is accused of providing spiritual inspiration for al-Qaida.

Mr Rawi was taken to Bagram airbase in Afghanistan - where he alleges he was tortured - and then to the US base in Guantánamo Bay in Cuba.

The British government at first claimed that because he was not a British citizen, it was not able to provide any consular or diplomatic protection.

The revelation about his assistance to MI5 led to a change of heart. In her written statement, Mrs Beckett said attempts to seek his return were begun in early 2006, "based on the particular circumstances in his case". She added: "We have now agreed with the US authorities that Mr Rawi will be returned to the UK as soon as the practical arrangements have been made. This decision follows extensive discussions to address the security implications of Mr Rawi's return."

It is expected that he will be questioned under anti-terrorism laws when he returns to the UK, but will be released after being fingerprinted and providing DNA samples.

Wahab al-Rawi, who last saw his brother in the Gambia after their detention and who claimed the CIA agents had threatened him with rape and torture before releasing him, said: "My biggest concern is that he is still mentally alert. He's had a long time in solitary confinement. "

Bisher al-Rawi's lawyer, Zachary Katznelson, who has visited him in Guantánamo on behalf of the campaign group Reprieve, said that his client's treatment amounted to torture. "We are grateful for British government efforts to secure Bisher's release from the black hole of Guantánamo Bay. However, the British government's job is not done. Nine other British residents remain," he said.

"All but one are kept in constant isolation, living in six by eight foot steel cells, with no windows and unrelenting electric light. One has been on hunger strike for over 100 days - tied down and force-fed twice a day. None of them are charged with a crime. Not one has had a trial."

Edward Davey, Liberal Democrat MP for Kingston and Surbiton, said: "Bisher al-Rawi is not and has never been a threat to national or international security. His case should be a lesson to us all that when you ignore natural justice, injustice follows."