To interview a jihadi is one thing, to live among jihadis quite another. To share their prison cells and their jail trucks on the way to a dictatorship’s trials is both a journalist’s dream and a journalist’s nightmare. Which makes Mohamed Fahmy a unique figure: in a prison bus, he hears his fellow inmates rejoicing at the beheading of a captured journalist in Syria. “They won’t let us out,” a voice shouts at Fahmy in Egypt’s ghastly Tora prison complex. “We haven’t seen the sun for weeks.” And he hears the rhythmic voices of prisoners reciting the Koran.

Fahmy, who is an Egyptian with Canadian citizenship, is the Al Jazeera English TV reporter who spent almost two years in his native country’s ferocious prison system, as a guest of President al-Sisi, locked up with two colleagues for being a pro-Muslim Brotherhood “terrorist”, fabricating news and endangering the “security” of the state.

The charges were lies and the trials that followed were a mockery of justice. And when Fahmy was eventually released to travel to Canada, he took with him an extraordinary account of life among those dedicated to the West’s destruction.

I should say at once that Fahmy is an old friend of mine, and his story is not as straightforward as it may seem. He and his wife-to-be first welcomed al-Sisi’s military coup, which overthrew the elected Egyptian Muslim Brotherhood president Mohamed Morsi, and Fahmy uses the word “terrorist” quite often – rather too much in my opinion – and when I last spoke to him this week, he was back in Cairo, preparing for a New Year holiday in the resort of Sharm el-Sheikh.

But in the fastness of Canada, he has written The Marriott Cell: An Epic Journey from Cairo’s Scorpion Prison to Freedom – a frightening account of his years of imprisonment, which should be a footnote in future history books on the jihadi struggle in the Middle East. (Why it has not been picked up in Britain or the US is a mystery.)

For Fahmy found himself both appalled by the self-righteousness of his fellow prisoners, but trusted and admired by them, because he too had fallen foul of the same cruel dictatorship. You can understand how this affects him. The Koranic recitations echo through Tora Prison’s verminous “Scorpion” section, and as Fahmy mumbles “half-remembered verses, my rational, Western educated mind rises up in protest – it is, after all, a group of incarcerated Islamists with whom I pray. I feel self-conscious. Silly almost... But a few of the prayers I learned as a young boy return and wash over me, drawing me along in their tide.”

On arrival in his cell, an army of mosquitos descending upon him, Fahmy discovers that he is imprisoned with men whom he was interviewing only a few months earlier as members of the Morsi government: Essam al-Haddad, Morsi’s executive aid who had met President Obama; Khaled al-Qazza, Morsi’s foreign affairs adviser.

But there are others. “I am Sheikh Murgan Salem al-Gohary,” a voice calls to Fahmy down the corridor. “I am a Salafist jihadist who fought alongside brother Sheikh Osama [sic] bin Laden against the Soviet and the American devils in Afghanistan, I have been married three times and I have many children. I don’t allow any of them to visit me to avoid humiliating them... This is all a play, a political performance by these pigs... Stick to the Koran.”

Murgan was a member of Islamic Jihad in Palestine with strong ties to the Taliban, twice sentenced to death by ex-President Hosni Mubarak. On an Egyptian television talk show, he had called for the destruction of the pyramids of Giza and the Sphinx – a true follower of the Buddha-smashing Taliban and the antiquity-exploding Isis. Fahmy notes that Murgan is known as “an angry and murderous radical”. Fahmy is appalled. “What a nut! Now I am living with him and he is giving me advice, too.”

Much to Fahmy’s distress, a number of other prisoners shout their support, praising Al Jazeera which had, at the time – to Fahmy’s horror, because his own reports were subtitled and used without his knowledge on the same channel – been carrying pro-Brotherhood material on its live Egypt network broadcasting out of Cairo. “You journalists have been sent here to see the truth,” a man shouted. “There is a reason why God led you here!” And then Fahmy discovers that some of his fellow Islamist prisoners had been filming for the Al Jazeera live channel. No wonder he was in his cell.

25 dead during mass at Egypt's main Coptic Christian Cathedral

The “Scorpion” unit of the prison is a “concrete tomb”. When Fahmy is taken for further interrogation, he finds himself in a police truck amid the Cairo traffic, and his companions whoop with delight when the driver’s radio tells of three policemen killed at a checkpoint. And they begin to sing: “Brandishing our guns along with our explosive belts... we will cut off the head of the snake.”

Fahmy’s neighbour, to whom he is handcuffed, is puzzled. “Brother, why aren’t you singing?” Fahmy manages to reply calmly: “I make jihad with my pen.” The man, Ammar – a boxer and bomb-maker, he admits – has just returned from Syria to make “jihad in Egypt against al-Sisi and his illegitimate regime”.

Fahmy meets Mohamed al-Zawahiri, brother of Ayman, the man appointed al-Qaeda’s leader after the assassination of bin Laden. “We are not bloodthirsty merciless killers,” he assures Fahmy. “We merely defend ourselves... demand our rights of establishing a governance based on Islamic sharia.” When Fahmy asks whether his connections in Sinai, where Islamists have been attacking police and troops along the Egyptian-Gaza border, might have led to his imprisonment, a man beside al-Zawahiri shouts: “What Sinai! Those are legitimate resistance fighters. Whose side are you on?”

Whose side, indeed? In August 2014, Isis released a video of the beheading of American journalist James Foley. In another prison truck, the radio news is greeted with a cheer from Fahmy’s fellow prisoners. Isis promises to kill another reporter, Steven Sotloff, if the US continued to bomb their positions in Iraq. Fahmy was a friend of Sotloff. “He must be a spy,” the prisoner handcuffed to Fahmy spits out. “Why would an American put himself in such danger otherwise?”

Fahmy knows why: risking one’s life to get the story, “to show the suffering, to try to make a difference, to stop the madness”. He listens, aghast, as another man says that “he’s just one American. What about the thousands of innocent Iraqis killed by the US?”

Then it is Sotloff’s turn. Fahmy sees the next video. “Steven, head and beard shaved, wears an orange jumpsuit... His small glasses, the round curves of his warm face, and the kind smile... are nowhere to be seen... He has the fortitude to hold himself upright.... I pray that his mind and heart were calm...” Fahmy is enraged “that this hideous man who killed Steven and I are being labelled with the same name: terrorist.”

Egyptian government offers concessions as street protests continue Show all 4 1 /4 Egyptian government offers concessions as street protests continue Egyptian government offers concessions as street protests continue Anti-government demonstrators lean against the tracks of a tank in Cairo's Tahrir Square GETTY Egyptian government offers concessions as street protests continue Anti-government protests in Cairo at the weekend SIPA PRESS/REX Egyptian government offers concessions as street protests continue People start clearing up the streets EPA Egyptian government offers concessions as street protests continue Egyptians shop at a vegetable market in Cairo REUTERS

But as Fahmy’s freedom draws near, he can barely contain his emotion at the thought of leaving his fellow prisoners – even though he will soon fly to Canada, marry his young Egyptian fiancee, take up a journalism professorship and then return as a correspondent to the Middle East. He shakes hands with a man under sentence of death. “For the past six months, these men, some of them jihadists who call death and destruction down on the world for an inhumane ideology, have generously shared their food and meagre possessions.”

Fahmy remains convinced that the torture and prison regimes of the Middle East are universities for future jihadis. He also fears for the future of his own profession. He quotes Adel Iskandar, a Canadian professor of Egyptian origin, on Al Jazeera’s coverage of Egypt during the military coup. “Al Jazeera picked a side in the conflict and ran with it,” he told Fahmy, “and when the station was unable to deliver coverage from the ground, they relied on footage and reports produced by Islamist opposition groups and armed militia factions. This technique became their modus operandi in Syria where the stakes and the costs are extremely high – particularly to journalists.”