A British man who survived an Isis attack has been released from a prison in Bangladesh after more than two years of being held without charge over baseless terrorism accusations.

Hasnat Karim had been celebrating his daughter’s 13th birthday at the Holey Artisan Bakery cafe in Dhaka on 1 July 2016 when militants burst in and massacred 22 people.

Relatives said the former university professor, who is a British-Bangladeshi national, was forced to act as a human shield by jihadi gunmen who threatened to kill his children.

Mr Karim and his family survived the atrocity, but he was imprisoned after being wrongly accused by Bangladeshi police of colluding with the terrorists.

Relatives travelled to British embassies and the Foreign and Commonwealth Office in London to plead for officials to secure his freedom, but the appeals came to no avail until Thursday.

Authorities released the father-of-two from Kashimpur jail in Gazipur after police filed a charge sheet that did not name him among the accused.

He is a British citizen. The British government did absolutely nothing to secure his release

“Mr Karim’s involvement was not found during any stage of investigations,” Monirul Islam, chief of Dhaka’s counterterror police, told local media. “That’s why we have not included his name in the charge sheet.”

Mr Karim’s wife, Sharmina Parveen, told The Independent she had feared her husband would be killed during the 10-hour ordeal.

Hasnat Karim leaves after his court appearance in the Bangladesh capital Dhaka on 13 August 2016 (AFP/Getty) (AFP/Getty Images)

“I think they chose him because they knew he would not run away if his family were there too,” she said.

“I cannot describe to you in words how it felt. They kept taking him away and then bringing him back and every time they took him I had no idea if we would ever see him again.”

The Isis militants massacred 22 people after ordering hostages to recite verses from the Quran and torturing anyone who could not, before the cafe was stormed by security services.

The victims included nine Italians, seven Japanese, several Bangladeshis and students from America and India, while Bangladeshi police admitted mistakenly shooting the restaurant’s pizza chef dead after mistaking him for a militant.

Isis published the names and photographs of militants who launched the attack but made no mention of Mr Karim, who lived, studied and worked in the UK for decades before returning to his country of birth to teach.

He became a professor in the business faculty of Dhaka’s North South University in 2008, where one of the attackers had studied, but later left to run his father’s engineering business.

Mr Karim’s sister, Sabera Khan, told The Independent he had never been associated with extremists or criminality of any kind.

“There was never any evidence, they searched every corner of his laptops, his phones, his offices, my family’s offices, they turned everything upside down – I don’t know why it took so long, I don’t know what they were looking for,” she said.

“It’s unbelievable because we didn’t know if he was going to make it out of the attack alive. We were so happy when he came out and then this happened.”

People help an injured person after a group of gunmen attacked a restaurant popular with foreigners in Dhaka, Bangladesh (AP)

Ms Khan said the British government had not been “responsive” to the case, even after she travelled from the US to the Foreign and Commonwealth Office in London to beg for help.

“The British government gave me just a textbook answer saying he’s in Bangladesh so we can only visit him from time to time,” she added. They did the bare minimum, I was disappointed they didn’t do more.

“He’s a British citizen – he studied in the UK, he did his engineering degree at Imperial College London, then a masters. He lived there for many years.

“Seeing that he was a citizen of theirs I didn’t think they did enough.”

A lawyer who acted for the family described the British government as “useless” and said they had “done absolutely nothing” to ensure Mr Karim’s release.

“He was allowed contact with his family once a month but his father died while he was in prison and he wasn’t allowed to go to the funeral and his mother is very unwell now,” the lawyer added.

Ms Khan said her brother’s family were overjoyed to have him home in Dhaka, with his son and daughter – now aged 10 and 15 – constantly at his side.

“He is resting but he said he can sleep,” she added. “He’s been sleeping on a floor for two-and-half years. They don’t have beds in prison, no pillows, nothing.

Hasnat Karim with his two children, who were with him and their mother during an Isis attack in Bangladesh

“He is having difficulty settling in, just the reality of it. I think he still has to work through that for a very long time.”

Ms Khan, who lives in the US, said her brother has not yet been able to talk about the night of the attack and has lost weight after suffering from stomach upsets and infections in jail.

Mr Karim’s wife lost her job as a teacher as a result of the baseless accusations, while their children were ordered out of their school but eventually allowed to return.

The family business has also been suffering after significant publicity around the police’s original claims in Bangladesh, and Mr Karim’s future remains uncertain.

The family are still waiting for authorities to return Mr Karim’s car, passport and those belonging to his wife and two children.

Kate Allen, the director of Amnesty International UK, said his detention had been “inhumane and illegal”.

“Hasnat Karim and his family were victims of a terror attack,” she added. “They should have never have been forced through two years of further trauma with Karim suffering unfairly behind bars – detained without charge and denied specialised medical treatment that saw his health deteriorate.

“The end of his suffering is a cause for celebration, but we must not forget that sadly, he is not alone in being a target of the Bangladeshi authorities’ arbitrary force of law.”