I was paying my bill at the hotel when they came. There were seven of them, stiff and formal in plain-clothes. “Mr Pelham?” asked the shortest one and presented me with a hand-written document in Farsi. “It’s been signed by a judge,” he said. “It entitles us to detain you for 48 hours.” He paused to allow the information to register on my face. “It might be less,” he added. “We just need you to answer a few questions.”

He gave me a choice. Either I could be questioned in the hotel or in their car on the way to the airport. “You might even make the plane,” he said. Almost automatically, I asked to see a lawyer or a diplomatic representative. He flicked his wrist, indicating that this was unnecessary. “All we want to know is a little bit more about your trip. There’s no need to delay or complicate things.”

It was 7.30pm. My plane left in four hours and the airport was over an hour’s drive from Tehran. The officials ushered me into a small office in the hotel and crowded around my chair.

“Your mobile phone and laptop, please.”

I pointed to the bag lying against the opposite wall.

“Are there more?”

I took a second phone out of my pocket.

The shortest man was in charge. He wore a dark, oversized jacket and trousers. His wavy hair was greasy and his face was lined. He bobbed up and down on a chair and patted my knee, though it was unclear whether he meant to reassure or threaten me.

The guards rifled through my books and notes. They held up a piece of paper with jottings on it from a previous trip and asked me to explain what I had written. I tried to hide my alarm when I saw that my eight-year-old son had stencilled large Hebrew letters on the back. How could I have brought that with me? I asked myself. But if they noticed the Hebrew, they said nothing.

I asked to go to the toilet. Like a child, I wanted to escape the tension in the room. I needed to calm myself by breathing deeply. That day, in a taxi back to my hotel, I had flicked through my emails and read that a number of travellers, including a French-Iranian academic from Sciences Po in Paris, had recently been detained in Iran on the pretext of violating state security. And now here I was.

The largest of the men walked closely behind me as we descended to the basement toilet. He gesticulated for me to leave the door open.

After I returned upstairs, I was led to the reception desk to finish paying my bill. Two black saloons were waiting outside and I was directed into the rear one. Guards wedged me in on either side and we pulled off.

The interrogation began as we drove. If anything, the officials’ interest in me was flattering rather than scary. After decades of being the interviewer, I had been promoted to being the interviewee. No one had ever found me so interesting before.

The short man asked me about my family, my education, the countries I’d visited and the languages I spoke. I told them Arabic, French and, after a pause, Hebrew. I was sure that this wasn’t news to them. They wanted to know how many times I had been to Israel. And Palestine, I added, to emphasise my impartiality. A radio crackled with static.

I was relieved when we arrived at the airport to be reunited with my bags. Just under two hours had elapsed by this point. But instead of checking in, I was taken to an office at the back of the airport hall with a big glass window overlooking the departure lounge. Polystyrene containers filled with half-chewed chicken bones and pellets of saffron rice lay on chairs lining the walls.

The status of those who had taken me was becoming evident – they had the run of the state’s vital infrastructure. A tall, bulky man, more suave than the others, was introduced to me as “the doctor”. He looked weary and irritated.

“Your phone password, please,” said the short man.

I told him that I always used my thumb print.

A hint of impatience followed almost immediately.

“There isn’t much time, if you want to catch your plane.”

I made a show of racking my brain and offered several phone passcodes, none of which worked. I had an app on my phone, which many foreign correspondents use, that notified my editors of my location every 20 minutes, in order to detect any unusual activity. I wondered if they had picked up anything.

“One last chance,” said the doctor.

This time, the code worked.

“You’re not co-operating,” he said with a frown. “It’s not a game. There’s not much time.”

I heard the last call for the Doha flight. “We’re going,” I was told. I was shocked at how easy it had all been and wondered where my ticket was. The short man escorted me away with his entourage. I could see the departure gate to the left of the check-in counters. We turned right.

The pace reached a frog march. Two men in front, two behind, past the plastic barricades separating check-in from the departure-hall entrance, past the x-ray machines and outside to the car drop-off. “Perhaps they know a shortcut,” I thought. An older, more battered car awaited us. I had been downgraded.

As we sped off, a blindfold was put on me. If I lifted my head slightly, I could just about make out my feet. After 15 minutes of chaotic driving, I was helped out of the car and led across the threshold of a building. When the mask was removed, I found myself in another office. I made a number of attempts to ask why I was being held. Each question was met with an order.

“Speak in Farsi,” I kept being told. “You know Farsi, don’t you?”

I insisted, apologetically, that I didn’t.

“Do you know the Koran?” asked one gruff guard, whom I would later come to know as Ali.

“Give me refuge in God from the accursed Satan,” I replied, quoting the liturgical Arabic phrase that precedes the recitation of the sacred text. He seemed amused.

“You’re taking hostages,” I said. “Why are you doing this?”

“Wait,” he replied (this turned out to be his favourite word).

Other guards brought in kebabs in polystyrene boxes.

“I don’t eat meat,” I said huffily.

As a substitute, I was offered coarse digestives and tea in a thin plastic cup that was too hot to hold. I was torn between anxiety and the need to get these people on side. I rejected the food. But the next time Ali handed me tea, I accepted.

The doctor entered the room and asked me to write down everything I’d done in Iran, day by day, meeting by meeting. Whatever I wrote, he would ask for more details. Finally, about nine hours after I was taken, I was led outside again. The guards told me to look up. A Qatar Airways plane loomed above us, ready for its dawn flight. It turned out that we had never left the airport. The last passengers were boarding. I felt a flicker of hope, but then I saw the guards smirking. A car was waiting on the tarmac. They opened the door and ushered me in.

The warm glow of dawn was breaking over the mountains to the north of Tehran. The guard told me I was being taken to a place that was a grade above a prison. He handed me a blindfold with an apologetic smile but allowed me to leave a slightly larger gap beneath my eyes and hold on to the seat in front. From glimpses of the chevrons I could see that the driver was zig-zagging in and out of the hard shoulder. “You’re supposed to detain me, not kill me,” I quipped. It earned a laugh but we didn’t slow down. We were clearly driving back to town and I tried to work out our route. Eventually we descended a steep ramp and stopped. I shuffled up two steps and, once inside, my mask was removed.

A Dickensian character awaited me, pale, short and slightly hunched. The hair on his head sprouted in clumps; his face and hands were covered in warts. He asked me to empty my pockets. I surrendered my belt and, more reluctantly, my glasses. He led me down a corridor, unlocked the last door on the left and signalled that I should enter. It was a large cell, perhaps 20 square metres, with a thin mat on the floor. He pointed to a pile of musty brown blankets folded in a corner. As I walked over to them, I heard the door clang behind me and the bolt pulled sharply across. Through a high window I could see the early morning light. I undressed and fell asleep.

Even in good times, Iran has a complicated, and at times paranoid, government. Elected parliamentarians give a veneer of democracy but power ultimately resides with the Supreme Leader, Ayatollah Ali Khamenei. The Islamic Revolutionary Guard Corps, the regime’s most powerful security force, answers directly to him. Rival arms of the state, including the security forces, jostle for influence. And the rules are unclear. Many regard Western journalists, particularly those asking awkward questions, as spies. Minders are ever present, with tape-recorders in hand to intimidate interviewees.

And this was a bad time in relations with the West. In April 2019 America declared the Revolutionary Guards to be a terrorist organisation. It had tightened sanctions, preventing Iran from trading in dollars or selling its oil.

I had been waiting for a journalist’s visa for three years when the Iranian authorities unexpectedly granted me one on July 1st 2019. On previous visits to Iran I had either been part of a large press pack covering elections, or with other colleagues from The Economist. I knew that the Iranian authorities were particularly suspicious of journalists who have been to Israel or are Jewish. I ticked both boxes. So I was apprehensive about my first solo trip.

Three days before I left for Iran, British marines impounded one of Iran’s largest oil tankers as it passed through the Straits of Gibraltar, suspecting it of breaking European sanctions by carrying oil to Syria. Iranian officials I knew assured me that I’d be safe. But the timing of the visa seemed odd. During the week I spent reporting, few of the meetings I requested materialised and those that did peddled the government line that Britain had committed an act of piracy. My hotel, once a favourite with foreign journalists, was dark and empty. But when I went to Friday prayers and tried to cover a rally supporting the strict enforcement of the hijab, I was turned away for being a British national. Iran was not in a welcoming mood.

I had gone to report on the impact of American-imposed sanctions. Some news stories were claiming that Tehran was on the brink of collapse, but I saw few signs of it. There was no panic buying. The city looked cleaner and more modern than on my visit three years before. It has the best underground in the Middle East, with locally made trains. Parks and museums were abundant and well-tended, pavements were scrubbed and the city’s many flower-beds immaculately maintained.

America’s sanctions had hurt people, of course. Average monthly salaries were worth less than a pair of imported shoes. I saw people sleeping rough or hawking junk on the streets. One former university lecturer I met had been reduced to busking. But few people went hungry and there seemed to be a joie de vivre among many of those I talked to. Cafés, theatres and music halls were packed. An earlier bout of sanctions had forced Tehran’s Symphony Orchestra to disband but I wangled a ticket for the opening night of the reconstituted Philharmonic.

Some canny operators even found ways to profit from sanctions. When Google and Apple dropped Iran from their services, local clones emerged. Snapp!, a ride-hailing app, claims to have more users in Tehran than Uber has in London. Shortages of certain goods, particularly medicines, have led to a proliferation of homeopathic shops around town.

Some Iranians I spoke to argued for tighter sanctions to bring down the regime or force it to resort to diplomacy. Even supposed loyalists privately said they hoped that a further squeeze in oil revenues might push the government into changing course. Others lacked the patience to wait. My government-appointed minder, who accompanied me throughout my week reporting, had surfed dating sites until she had found an Algerian-French student willing to marry her and send her a visa to France. She was half my age but habitually behaved like a Victorian nanny, taking my arm as we crossed a road. When I was arrested at the hotel, she sat at a coffee table in the lobby, writing a statement and refused to make eye contact.

The sun was already high when I woke on my first morning in detention. It was a scorching day but a half-hearted air-conditioner dulled some of the heat. No sooner had I stood up than my jailer unbolted the door to bring me a metal tray with thin naan bread, yogurt and water. He handed it to me and pointed across the corridor to the latrines. A shower spout hung over the hole in the ground but I couldn’t see any towels or soap. The cold water was refreshing.

How had the guard known I was awake? Without my glasses, the high ceiling was blurry but I could make out the eye of a camera over the door. Previous occupants had scratched tallies on the wall in groups of five, suggesting that I might be here for a while. I paced the cell and tried to enlarge it by imagining that each wall was the boundary of a field back home in Gloucestershire. The bedside wall ran through the pastures to the hedgerow, which stretched along the wall with the door. I turned and walked through the woods, along the edge of the sheep field and back to my bed.

The countryside stroll helped me to expand my perspective. It was Monday morning in Britain but I couldn’t be certain that anyone there would have registered that I was missing. My wife would be getting our children ready for school, waiting to hear from me. She was heading off to Paris to research her latest book and I had promised to be back in time to take over. I was letting her down again. Perhaps my colleagues were also starting to worry.

The experience wasn’t entirely unfamiliar. I had spent several short spells in prison. I had been held for hours in northern Yemen in 1997 where I’d been trying to report, and endured a long weekend in a cell in 1999, at the crossing point between Gibraltar and Spain, accused of smuggling goods into Spain (in fact I was trying to furnish my flat in Morocco). Hostage-taking had become horrifyingly familiar when I was a correspondent in Iraq. I knew that, with natural light and a large cell, my conditions here were pretty good.

My mind spun all sorts of fantasies. I drew up a cost-bene­fit analysis of my circumstances. If word of my capture got out, it could damage my chance of early release but boost sales of an update to my book. My jailer, who until now had communicated entirely in grunts, might teach me Farsi. The spartan diet might help me lose weight.

I launched into my exercise routine to ward off sciatica, which ended with bent knees and prostrations, forehead to the floor. The bolt shot open and my jailer peered in. Had he thought I’d converted so quickly? Or that I was having a heart attack? Sub be-kheir (good morning), I assured him and he replied in kind. I had elicited his first words.

Over the next few hours I exercised my toilet rights frequently. The knock on the door allowed me to control the timing of our encounters, which gave me a semblance of control. The guard seemed pleased to be relieved of the boredom, and on each occasion he would grunt a new phrase – khosh bakhtam (nice to meet you), asr be-kheir (good afternoon) – and take a fraction longer to lock me in again. “Would you like more,” he asked, pointing at the water jug as if encouraging me to increase the frequency of my toilet visits.

On my second day, as dusk glowed, my jailer brought a blindfold and led me awkwardly along a corridor. When he took the mask off, I found myself in a room that was divided down the middle with a one-way mirror that I couldn’t see through. The doctor was waiting. He took a cursory glance at me and then disappeared. I heard someone entering the room on the other side and the squeak of chair legs. A shadow introduced himself as my translator.

“It’s my job to sound aggressive. Try to understand,” he said apologetically, before the doctor returned. The translator had looked me up online and wanted to know how he could buy my books. He sounded a little too friendly, which made me worry about where all this might be heading.

The doctor appeared again. He moved behind my chair and put his hands on my shoulders. “We need you to co-operate,” he said.

I replied that I had nothing to hide. He continued in Farsi, but the translator did not translate.

“What’s he saying?” I asked the mirror. The Farsi continued.

“Reply in Farsi,” the translator ordered.

“But I don’t speak Farsi,” I protested.

“We know you speak Farsi.”

I apologised. “I would love to learn,” I said, and suggested we talk in Arabic.

The doctor relented and continued in broken English embellished by the translator. He told me that I would be transferred to a more comfortable location while they carried out their investigations and questioned me further. This was a favour, he said, but the decision could be reversed if I didn’t co-operate, a threat that soon became recurrent. He hoped he could spare me from prosecution in court.

My experience in solitary had lasted, I guessed, less than 12 hours. What a pale imitation of a political prisoner I was.

They took me to my new home, a shabby flat on the top floor of what seemed to be a hotel fallen on hard times. There were two sofas, an armchair, a rectangular glass coffee table and a TV that stood against the wall. Faded orange curtains covered windows that stretched along one side of the room. A wooden kitchenette occupied a corner. Two bedrooms led off from the other side and the guards gestured for me to rest in one of them. When I closed the door, they opened it again. That night I was made to bring a mattress into the sitting room and the guards left the lights on while they watched over me until dawn.

On my first evening in the flat the doctor, his assistant Ali, and another translator turned up and stayed late into the night. Again I asked to contact my embassy and a lawyer. That was a thorny path, they advised. It might lead to a lengthy court case, or incarceration in the notorious Evin prison. “You know what happens in Evin,” the doctor said.

When I had arrived in Tehran I had dined with an economist who had recently emerged from a month in what alumni call Evin University, 21 days of it in solitary confinement. The torture, he told me, was psychological rather than physical. He insisted he was unharmed, but his hair had turned white since I had seen him three years earlier.

My captors wore no identifying uniforms, but on the second day the doctor told me that he was an officer in the intelligence arm of the Revolutionary Guards. Iran’s security agencies are many tentacled. In 1979 the new Islamic Republic retained much of the existing state apparatus, including the army and a good part of the bureaucracy, but it added another tier to keep existing institutions in check, and the parallel systems have competed ever since. The government’s own intelligence ministry would be unlikely to detain a Western journalist whose entry it had approved. My accusers were from its more powerful rival.

From the first months of the 1979 revolution, when the Revolutionary Guards took 52 people hostage in the American embassy, the Corps has had a record of detaining foreigners. In the 1980s Hizbullah, Iran’s Lebanese proxy, imprisoned Western envoys, teachers and journalists. Iran itself had started making arrests again. Many of these detainees were dual nationals, including Nazanin Zaghari-Ratcliffe, a British-Iranian who has been held since 2016. But some of them had no Iranian citizenship. The threat being made against me was clearly a real one.

It was a surprise when the doctor said that I could dictate a message to my wife, which his men would send from my phone. The brief text was a testimony of my devotion and guilt, combined with a cry for help that might be bland enough for them to relay.

“Darling Lipika so sorry not to make it back in time for your trip tomorrow .i have been held since last night in Tehran and am being questioned. I have not been hurt and so far am being well looked after , i will contact you tomorrow morning . Don’t worry , it will be ok . Love you to the end of the earth nico.”

In the days that followed, there were always three men present to watch me; each shift lasted 24 hours. Being crammed with my guards into a small flat, spending our days in close proximity in T -shirts and underpants, was a surprisingly intimate experience. Over time much of the guards’ suspicion dissolved and they seemed to be concerned less that I might try to escape than that others could break in. Were they fearing a Hollywood-style hostage rescue by Western goons, I wondered, or a rival arm of Iran’s intelligence services seeking to grab their latest asset? They left the key to the apartment temptingly in the lock. But a knock on our door sent them into paroxysms of activity, even when it was just the arrival of a takeaway meal. They would draw their pistols from their back pockets and brace themselves behind the heavy cupboard that they had wedged against the door. One guard angled the cupboard back a few inches, the other cocked his pistol and extended his arm. Then they would open the door just wide enough to instruct the delivery man to leave the food outside. Only when they heard the lift descend would they retrieve it.

One guard assumed the role of language teacher. I pointed at objects, he said the relevant word in Farsi and we practised pronouncing it together. We had just moved onto phrases when he left. Another insisted we exercise together, so we sat on the floor facing each other, intertwining our legs to perform sit-ups. After a day he suggested we dance to Iranian love songs, which he played on his mobile phone. He pirouetted around the room, rotating his hands and gyrating his pelvis. The rest of us made a pretence of joining in, largely to encourage him, and then stepped back to enjoy the spectacle. Each time I felt that I had developed a rapport with a guard, he would be replaced.

Over the course of four days the men spent most of their time glued to phone-screens, watching Bollywood films, or American or Chinese schlock full of street fights, which they accessed through virtual private networks to evade the censorship they were supposed to enforce. They ordered kebabs, pizzas and watermelon and never cleared up. Each morning, I would wash their plates, scrape the leftover watermelon rinds, pizza crusts and kebab gristle into the bin and make tea. I would sigh audibly, like a father despairing of his unruly kids. “Thank you,” they apologised.

I scoured the flat for signs of where in Tehran we might be. The only marks on the crockery read “Made in China”. The takeaways came from a Tehran chain. Whenever I thought the guards were asleep or absorbed on their phones, I would peek through the gap between the curtains. We were six storeys up, and the narrow street was lined with tall plane trees whose tips reached the floor below. The street sloped upwards to the right, but not steeply, so I guessed we were in the lower reaches of northern Tehran. In a city of 15m people that wasn’t much help. I got excited when I found “Hotel Johnson” written on a faded, cream-coloured hairdryer. (Later I discovered that this was simply the name of a brand.)

My interrogators visited each morning, but by the third day the mood had lightened. I was allowed to sleep in my room with the door open. The doctor explained that he needed to continue his enquiries, but in the meantime I would be transferred to a more comfortable hotel. I was not allowed to do any journalism but was permitted to roam the city, so long as I kept Ali notified of my movements and any meetings. As a journalist I had a minder to monitor my every move and conversation, yet now I would be able to wander around freely.

The guards gave me back my belongings an hour later. My phones, laptop and notebooks were missing, but my son’s Hebrew stencil was still there. The devices would be returned, Ali promised. In the meantime he would arrange a substitute smartphone.

I shook hands with my captors. I may even have said “see you again”. I donned the blindfold like an expert and was led out of the apartment and into the lift. Once we were back on the main road the mask was removed. This might have been an evening drive with old friends. Twenty minutes later we arrived at the Simorgh hotel, where I had stayed on previous trips, in the ritzy north of Tehran. The doctor was waiting to check me in: $50 a night, he said. Feel free to make international calls. The Revolutionary Guards would pick up the tab.

I hesitated before stepping beyond the lobby of the hotel. My first trip was to the laundrette 50 metres up the road. As the owner started chatting to me, I realised that I had interviewed his brother in my first week in the country. I asked him to pass on my good wishes and dared myself on to the bookshop a little farther uphill and then into the sculpture park beyond. I wondered about treating myself to a decent meal, but I didn’t feel like eating alone. And I didn’t know what the limits imposed on me actually were. My first foray lasted for barely half an hour.

After that, each time I went out I would venture a little farther before returning to the haven of the hotel. I knew several people who lived nearby, but avoided contacting them. At one point I ran into someone I had interviewed only days before (he had taken me to see a Farsi version of “Waiting for Godot”). He looked shocked to see me, knowing that I’d been planning to leave shortly, but I brushed off his questions. Self-censorship ranks as one of an authoritarian regime’s strongest tools, and I was complicit.

Despite Iran’s pious reputation, Tehran may well be the least religious capital in the Middle East. Clerics dominate the news headlines and play the communal elders in soap operas, but I never saw them on the street, except on billboards. Unlike most Muslim countries, the call to prayer is almost inaudible. There has been a rampant campaign to build new mosques, yet more people flock to art galleries on Fridays than religious services. With the exception, perhaps, of Tel Aviv, I had visited nowhere in the Middle East where people read as voraciously as Tehran. “The Handmaid’s Tale”, Margaret Atwood’s dystopian fable of women enslaved to a theocratic caste, is a particular favourite, the owner of one bookstore told me.

The more I delved into city life the more colourful I found it. I met a raver who’d been partying in Los Angeles and Paris but, he said, “nothing compares to Iran”. Plastic surgeons were so accomplished that an English porn star supposedly chose to get her nose job done in Tehran.

Life in Iran has always swung both ways. Nothing goes and everything goes. Alcohol is banned but home delivery is faster for wine than for pizza. A portrait of Ayatollah Ruhollah Khomeini, who founded the Islamic Republic and ranted against music, hangs over the stage in concert halls across the country, glowering at thrilled audiences. The palpable sense that you might become a target only adds to the abandon with which some people live.

The space for veil-free living had grown since I last visited. In the safety of their homes, women often removed their head coverings when chatting over the internet. Darkened cinema halls offered respite from the morality police who enforce discipline. In cafés women let their scarves fall languorously. The more brazen simply walked uncovered in the streets, risking imprisonment. And, in an unusual inversion of rebellion, ties have made a reappearance some 40 years after Ayatollah Khomeini denounced them as a symbol of British imperialism. (The conductor at the Philharmonic wore a bright-red one.)

Many restrictions have peculiar quirks. A female actor may not show her own hair on stage, but is allowed to wear a wig that makes her look ravishing. She can sing but not perform a solo. And she can dance, but not in public.

I found myself drawn to the exuberant side of the capital’s life. The listing of plays in Tehran was almost as long as London’s West End and I devoured them. Directors are adept at finding ways to evade the censors. A striking number of plays and films I saw were set in prisons – a commentary on the Iranian condition – but under bygone regimes. Opera was taboo, but a performance one evening in the red-cushioned opera house of the former shah, which was billed as Kurdish folk music, included Verdi. Beneath a vast glittering chandelier the audience threw bouquets of flowers at the Iranian singer, who is acclaimed in both Rome and Berlin; for an encore, she finally dared to sing a solo.

The most extraordinary performance I went to in these strange weeks was a production of “The Sound of Music”. I thought initially that the audience’s enthusiasm was testament to Tehran’s thirst for Americana, but the tale of 1930s Austria was remarkably apt for Iran today. The nunnery looked oddly like a women’s madrassa in Qom, the country’s religious centre, and the audience seemed thrilled by a female rebel challenging the stifling atmosphere. They sang along when she escaped to the hills and sighed when, pricked by pangs of conscience, she kept returning. The finale was given an Iranian twist. In the original, Maria and her charges escape from the Nazis to freedom. Here, instead, they traipsed across the stage as voiceless refugees dragging battered suitcases, a caustic reminder of the fate of those who flee their homeland. Instead of the family singing the last song, a triumphant phalanx of clergy and Hitler Youth did so. A giant Nazi flag filled the backdrop.

Of course not everyone got away with pushing at the strictures. In my first week in Tehran the authorities pulled a production of Ibsen’s “Hedda Gabler” – the play is about suicide, which is forbidden in Islam – and another about poor women reduced to hawking to feed their families. Cafés that hosted live bands risked closure until they had paid off fines. Women without head-coverings who were spotted on one of Tehran’s many surveillance cameras received police summons by text. But the morality police, who drove around town in new green-and-white vans, seemed too stretched to suppress every challenge.

One evening I stumbled on a crowd clapping to the jig of a violinist. They had formed a circle around a pair of male dancers who were sensually gyrating and rotating their wrists. People were cheering them on when the park lights suddenly cut out. Blackouts are rare in the city, so the presumption was that the authorities had pulled the plug after a tip-off or noticed the gathering on a camera. Boos erupted from the darkness. Someone shouted “Pahlavi”, appealing for help from the long-deceased shah. A minute later an electricity generator began to roar.

Though my afternoons and evenings had become more pleasant, on most mornings the Guards would question me, often for hours. It was more informal than in the early days. They would come to the hotel, invite me for coffee and we would drive through the traffic while they probed me on everything from my views on Israel and Palestine to sanctions and even Brexit.

Sometimes they would run out of questions and conversation began to flow in the other direction. The doctor confided in me of his fatigue. He slept for only an hour each night, he said: as well as being an intelligence officer, he was an academic and wrote a newspaper column.

As time went on, the Guards’ visits grew rarer and shorter. “You miss me, don’t you,” joked Ali when I called to ask where he was. But I had other handlers too: my wife and a tight circle of colleagues in London who grew ever more engaged through WhatsApp and phone calls. Initially they presumed that I was bored and they needed to boost my morale. One sent me breathing exercises and others challenged me to athletic feats of swimming and running. Sometimes I resented their interruptions. I felt as if I’d been given a key to a secret garden and was repeatedly being hauled back. My colleagues worried that my explorations were putting me in danger. I found their attention both comforting and burdensome. I felt pressure to make them feel I was worth supporting, but struggled to make my conversation sparkle and to convey my enthusiasm for a speedy return.

It was liberating to have the run of Tehran, without minders, deadlines or chores. But of course, I wasn’t truly free. I policed myself on behalf of the regime, becoming my own jailer and censor, aware that any lapse could have consequences. Sometimes I tried to speak over colleagues or relatives who were saying things that I feared might enrage my captors. I felt the presence of hundreds of electronic eyes. The friendliest faces who greeted me might be informers. And I could not leave Iran. It is an odd experience to know that you can be caught out at any time. But this was the way of Tehran. Some avenues open up, others close. Everyone feels like a captive. There are those who say that it is all a grand plan of the ayatollahs to keep people on edge.

On the tenth evening of my captivity, the doctor came to my hotel, smiling. Their investigations had concluded that I was indeed a reporter. I was free to leave the following Tuesday, in five days’ time. All that remained was to complete the paperwork for my exit visa. He hoped I would come back to the country and would stay in touch. Ali asked me to send him a picture of the Emirates Stadium, where Arsenal Football Club plays. I would be home in time for a family camping holiday and could see my father, who was ill and getting worse. I would relieve my anguished colleagues. I was finally able to acknowledge the fate I was being spared. On a whim I could have been locked up for months, perhaps years.

But when I asked Ali whether the office in London should book a flight for me, he told me to wait. I struggled to deal with the anticipation of my family and colleagues as well as my own. I went shopping for presents. I bought my wife a handcrafted ring, a silver thorn that spread out over several fingers, and a painting of a sleeping woman that I half-suspected the authorities might seize on my departure.

Until now I’d felt that my answers to the interrogations mattered, that the Revolutionary Guards were keeping me because they were genuinely suspicious about my activities. In a system where every foreigner – and many Iranians – were considered spies until proven innocent, I hoped to reassure them and clear the way for more regular reporting trips to Iran. As my exit visa failed to materialise, my naivety dawned on me. I was caught in a political game involving high-seas tankers and international diplomacy that far exceeded my ability to influence it. On July 19th, two weeks after the British government seized an Iranian oil tanker, the Iranians impounded a British-flagged tanker, for allegedly breaking maritime rules.

The day of my supposed departure came and went, and so did the doctor. Though he was my captor, he had also become a reassuring figure to me. Without him I grew agitated and anxious. There was silence from my handlers, and my case seemed to be in limbo. Weeks passed.

On August 15th the British government released the Iranian ship. But the Guards were digging in. Although the Iranian tanker was sailing again it couldn’t offload its cargo. Under American pressure, Mediterranean ports repeatedly turned it away. I feared either that the Revolutionary Guards thought they could use my presence to negotiate some kind of deal, or that I was becoming a pawn in the internal rivalry within the Iranian government. I was beginning to see at first hand the glaring tensions between the two arms of the state. My hotel seemed increasingly nervous about hosting an over-stayer without a passport. In an attempt to evict me one evening, they cut the lights and blamed an unfixable electrical fault. The following morning the Guards arrived to transfer me to another location. En route we were chased by two motorbikes and careened up and down the alleyways of northern Tehran. Only when we pulled into a cul-de-sac did the Guards succeed in shaking them off.

Once I was settled in another hotel, Ali resurfaced with a less sophisticated set of interrogators, also from the Revolutionary Guards; these included the short man who had first detained me. The questioning became both more formal and more threatening. And instead of meeting in Ali’s dusty car, I was summoned to a small block of flats near Revolution Square in the city centre.

A new interrogator – toad-like and clad in leather – told me that the Guards had found incriminating material on my laptop that touched on matters of national security: he had found a note from a conversation I’d had with a government flunkie about smuggling rings connected to the offspring of senior Iranian officials. This proved, he said, that I had crossed the line from journalism to espionage. They were reopening the case.

Ali’s smile had vanished. He unsettled me by passing notes or whispering in the ear of his superior. The new interrogator demanded information about an Iranian journalist whose name he had found on my computer, and accused me of bribing him. Notes he had discovered on Iran’s spiralling brain drain confirmed, to his mind, that I was seeking to undermine national morale. He asked me who I had been trying to recruit. Again he raised the spectre of being tried in court for spying.

Over my hotel breakfast one morning I read in the paper that Iran had sentenced an Iranian who worked for the British Council to ten years in prison for espionage. The regime intended to make Britain pay heavily for seizing its ship. As the stand-off over the tanker’s cargo intensified, I felt that I was being used to relay their muscle-flexing back to London through the phone the Guards had given me. Peculiarly I had become both hostage and intermediary.

Despite a month in the company of Iran’s Revolutionary Guards, I realised how little I understood the world view they were paid to protect. I wasn’t even sure how genuinely religious many of those I had met were. When we drove about town, Ali talked of his student days, his young family and his passion for British football. Ideology rarely came up. Within the parameters set by the vice squads, Tehran’s dominant culture was defiantly secular. Iran called itself a theocracy, yet religion felt frustratingly hard to locate and the truly religious seemed sidelined, like a minority.

As August reached its finale, I finally saw popular religion explode onto the streets. Muharram, the first month of the Islamic calendar, was approaching. At this time the death of Hussein Ibn Ali, grandson of Muhammad, is remembered. Commemorations culminated in Ashura, on the tenth of the month, when Hussein was martyred. For Shia Muslims, who dominate Iran, this is the most important rite of the calendar. Municipal workers festooned roads with bunting and flags and erected hundreds of stages across the city to re-enact the tragedy.

On the first of Muharram a solemn quiet fell over the city. From the flats behind Tehran University, which the night before had blared with dance music, I could now make out the faintest thump of chest-beating and the jangle of chains. I followed the sound down a passage, which was decked in black cloth and pictures of young martyrs killed in Iran’s wars, then descended several steps into a small vault hung with black flags and illuminated by a single red bulb.

I might have mistaken it for an S & M dungeon. In an odd way, it was one. I could see a room filled with shadows. Men sat cross-legged or crouched on their knees in a semi­circle around a small dais from which the chief mourner rhythmically intoned laments into the microphone. The silhouettes beat their chests, gently with one fist at first, and then more vigorously with two, as the chief mourner gained volume and pace: “O you, mathloum, you, oppressed.” He began to hyperventilate. A few mourners had stripped down to the waist. They shook their heads and slammed both hands onto their skulls. The mourner chanted Hussein’s name over and over hypnotically: “Husseyei, eeyei, eeyein,” in time to a recording of what sounded like flagellation chains. Finally, the story came to the point where the imam was slain. Then the strip lights came on, ending the reverie. Relieved by the catharsis of crying, a group of twenty-somethings spilled out onto the street in fits of giggles.

Though there are government-authorised Husseiniyas, this was not one of them. I had assumed that the clientele were zealots but those I spoke to afterwards turned out to be computer programmers, internet marketers and trainee lawyers. Some had been out partying the night before.

For ten nights in Muharram these passion plays were performed with growing fervour. Even an irreverent man who taught me Farsi, who devoted much of his spare time to picking up waitresses in cafés, said Muharram was the one religious occasion he observed. The streets were lined with mokebs, stalls offering tea and dates and decorated with tragic representations of the battlefield using decapitated toy soldiers. At one mokeb, I came across a camel being readied for sacrifice. Many of these rites drew on ancient folklore rather than Muslim practice, akin to the celebration of Easter in the West. Since its inception the clerical regime had sought – and failed – to purify Iran of its non-Islamic elements.

Amid the honeycomb of alleyways that make up Old Tehran, I visited an old garage that had been hung with black sheets to convert it into an informal Husseiniya, beyond the scope of the government’s authority. Again the mourners sobbed as they prayed. Afterwards, I stayed behind chatting over sweet lemon tea. “You feel a direct connection between people and God here,” a 40-year-old programme manager told me. He had stopped going to government mosques altogether, he said. Like some other pious Iranians I met, he feared that politics had sullied their religion rather than elevating it.

Early one morning, I went to hear Alireza Panahian, a preacher who is considered the intellectual lodestar of the Revolutionary Guards. He is known for his clarity, directness and harsh views on liberals and clean-shaven civil servants: in 2009 he had called for candidates who stood in the presidential election against Mahmoud Ahmadinejad, a fellow hardliner, to be eliminated.

I arrived late for his 7.30am sermon in a modern Husseiniya whose concrete bulk, seven-storeys high, soared over old Tehran. The vast ground-level arena was already full. Panahian preached from a cushioned, teak throne beneath a vast chandelier while his acolytes crowded around him on the floor. He projected so much power, I got the feeling that if he’d read from a phone directory his disciples would still have sobbed. “Are you a servant of God or of man?” he said, scanning the crowd for suspects. “Choose between the tyranny of westernisation and God.” After he’d left a woman in a black chador took me aside. I steeled myself for an ideological harangue. Instead, she held up a plastic bag of bread and a plastic container of beans that the Husseiniya distributed after the sermon. “That’s why we came,” she said. “If you ask about the contents of the sermon, no one can tell you. If you ask about the contents of breakfast, they’ll all remember.”

My interaction with London was now constant and I felt like I was living a parallel existence. I had been shaken by the latest twist in my interrogations and felt the need for solace. Though Ali, my interrogator, had repeatedly said I was free to visit Tehran’s synagogues. I wondered whether this might be a trap. It was possible that the Iranians even thought I was an Israeli spy. My colleagues in London warned me – obliquely but clearly – not to explore Tehran’s Jewish community. And still I was drawn to it.

Half of my mother’s family had been well-to-do cotton merchants from Alexandria’s Jewish community, the other half were among the first wave of Zionist migrants to Palestine in the early 1880s. Their history encompassed the process of rupture that has made the modern Middle East so combustible, and had led me to study Arabic and Hebrew at university in a vain attempt to overcome the dislocation of the past.

I tried to make time to search for vestiges of that lost pluralist world whenever I was in the region. Yet in Tehran, I dithered. I spent hours perusing glasses in the lower end of Palestine Street, where almost every shop was an optician, plucking up the courage to venture farther on. This was an area where a large number of Jews lived and, as I browsed, I wondered which of the high walls along the street might hide a synagogue.

One Friday evening, about five weeks into my captivity, I was walking back from Palestine Street to my hotel. Twilight had turned to dusk. I saw three men wearing black felt skull-caps talking by a bench. I still hadn’t chosen a new pair of glasses and I doubted my eyes. Nowhere between the Jordan river and Bombay had I seen Jews display their religion so openly, particularly in Iran, Israel’s inveterate enemy.

An iron gate across the road stood ajar. I peered in through the gap. I walked up the steps of the building and into a hall decorated with Hebrew script. I could see the rostrum from which prayers are led, and the ark that contains the Torah scrolls. People looked at my bulging pockets with suspicion. In their eyes I must either have been a bad Jew for carrying on the Sabbath, or no Jew at all. They mouthed Hebrew greetings and I replied, as if uttering a password. They invited me back for the morning service the next day, as long as I didn’t bring anything with me.

I didn’t go. I had a Farsi class until 1pm. And I was still worried about the consequences. I continued my search for a new pair of glasses, and found myself at a different open door on the other side of the street. I climbed two flights of stairs, passed a huge painted menorah and entered another synagogue. A rabbi was addressing an all-male audience. I edged forwards. A man with a bushy beard as long as an ayatollah’s ambled over with melon, cake and a smile. He introduced himself as Daniel.

Over the next three weeks Daniel welcomed me into the largest and most vibrant Jewish community in the Muslim world. Since the ayatollahs toppled the shah, Iran’s Jewish population has shrunk from 80,000 to around a tenth of that number. The ayatollahs have largely kept the remaining Jews safe, but they have also confiscated some of their property, particularly that of those who have left the country. Tensions between Iran’s Jews and the regime ebb and rise depending on the country’s relationship with Israel. But over time the Islamic Republic seems to have grown more at ease with the community.

Iran has 22 mikva’ot – pools for ritual immersion. Many of Tehran’s dozen active synagogues are vast and packed with worshippers. The synagogue where Daniel worshipped held four different morning services each day, he told me, as though encouraging me to sign up.

There was a Jewish café, two kosher restaurants and a maternity hospital funded by the Jewish community in the south of Tehran, where less than 5% of those born were Jewish. A Jewish sports centre was also under construction. Daniel often texted me first thing in the morning to find out whether I was coming for shacharit, the morning service, and later on to check if I was still on for maariv, the evening one. He would invite me for dinner in a heaving, cavernous kosher restaurant in the basement of the synagogue where we had met. Farsi greetings were spliced with Hebrew and Yiddish: “Shalom bashid”.

I went to one of the six weddings that a nearby synagogue was hosting over the following fortnight. The women glittered in sequins and wore towering stilettos, looming over the men. There was barely a veil in sight. Each table had several transparent plastic bottles of a spirit that aspired to be schnapps. After the starters the wedding hall transformed into a disco. Young and old jived to Farsi and Hebrew tracks. Strobes flashed. Fireworks flared. The Islamic Republic seemed a world away.

The community knew how to protect itself. Israel’s atrocities in Gaza in 2008 were still denounced on the Jewish Committee’s English-language website. The interior of each synagogue was decorated with Jewish symbols, but the high exterior walls were unadorned and the doors almost shut, even on the Sabbath. Daniel and his sons walked home in their skull-caps, but they kept their eyes to the ground, avoiding contact with strangers.

Though the sense of community, even family, added to the surreal nature of my captivity, it also felt comforting. By rare coincidence the first service of selichot, the penitential prayers recited for a month in the run up to the High Holidays, began on the first day of the solemn month of Muharram. The synagogues were packed. At 1am Iran’s largest synagogue still teemed with families. At 2am the congregation swayed in prayer for Israel and its people. The communal chest-beating was gentler than in the Husseiniya, but more ardent than in Western congregations. Women walked up to the ark and kissed the smooth Isfahani tiles painted with menorahs and stars of David, acting like Shia pilgrims at their shrines. People milled around on the street outside chatting. I must have recited my prayers for forgiveness with conviction. Daniel smiled as he swayed next to me, as if he knew he had won.

I had been captive for about six weeks when Ali called and told me to meet him on Vanak Square in uptown Tehran. He was in his car, late as always, and drove me to a park. It felt like old times. We walked towards the pedestrian bridge that connects two of Tehran’s northern hills and he apologised. The situation had gone on too long, he said. The Guards knew that my father was ill. Of course, he wanted me to see my family. But his superiors still had their doubts about me, he said. Though he hoped to convince them otherwise, he strongly doubted that the paperwork would be sorted out anytime soon.

Ali was merely doing a job. I should have known better than to feel deceived. Still, as August turned into September, my perspective began to shift. My interest in Iran waned for the first time. The cafés all seemed the same. I was running out of museums to visit. The Guards wouldn’t help when a university turned me away from a Farsi course because I could not produce my passport. I missed the party my wife and I had long planned for our son’s ninth birthday. I retreated to my room for much of the day and spent the evenings alone.

My mood swung according to the headlines in the Iranian papers each morning. “Iran not seeking confrontation, Zarif says in message to Johnson” spelled a good day. “Majlis [the parliament] moves to retake oil money from UK ” left me overcast.

The walk in the park clearly hadn’t resolved matters. Soon after, Ali called to summon me back to the interrogation room south of Revolution Square and then, just as I was about to enter, my mobile pinged. It was a message from Ali: “Do not enter.” It offered no further clarification.

Three days later, on September 4th, I was having my usual breakfast of dates and yogurt at the hotel when I got another text from Ali telling me that my exit visa was at the foreign immigration office downtown. “Go at once and ask for Colonel Aroubi,” he said.

“But my passport?” I questioned.

“It’s with the hotel,” he replied, as though it was obvious.

I had been asking for weeks for my documents. Now, I went over to the receptionist whom I saw each morning. He disappeared into a room at the back before emerging, clutching a familiar, tattered red passport, so worn that you could no longer make out the words “Great Britain” on the front. He handed it over. Perhaps it had been there all the time.

The immigration office was full of people lining up at glass-fronted counters to get their paperwork sorted before the Iranian weekend. I asked for Colonel Aroubi and was ushered into a side office. Procedures needed to be followed, the colonel insisted. He wanted to issue an exit visa, but since I had overstayed, he needed the approval of those who had sponsored my reporting trip. He seemed either unaware or unimpressed that my long visit was down to the Revolutionary Guards detaining me.

“But I already have official approval to leave,” I protested.

“From whom?” he asked. There was no reply when I called Ali. The Guards, it seemed, did not want to admit that they had held me. It was now 11am and the visa office would close in three hours. “You’d better hurry to your sponsor if you want it today,” the colonel advised.

Formally my sponsor had been the Ministry of Culture and Islamic Guidance, which vets visas for foreign journalists. I got a taxi through town to its office. Just as I was about to enter the door to the foreign-media department, Ali phoned. “Please wait,” he said. He clearly didn’t want me to deal with a ministry that was a rival power centre to the Guards. I sat on the street outside. Another hour passed. At last Ali called back with instructions to return to the immigration office.

It was now almost 2pm. I completed the paperwork and the head of personnel offered me tea, biscuits and chocolates from the glass bowl on his desk. I declined and handed over my passport so that he could get on with completing the formalities. But he was in a talkative mood and seemed in no rush. The prospect of leaving that day was slipping away.

He took a call and left the office. A few minutes later two men in black entered and introduced themselves as officers from another branch of intelligence. They apologised profusely for the difficulties I had faced and blamed the Guards for the inconvenience. They hoped that I had been well treated and expressed outrage that the Guards had made me pay my own hotel bill. They assured me that they’d been working strenuously for weeks to fix matters. My ordeal was over, they said. But could they just ask a few questions first?

After 40 minutes of interrogation, they disappeared. Ten minutes later they were back with embarrassed smiles. One awkward matter needed resolving. Because I had overstayed my visa, I needed to pay a fine of 4m toman, about $200.

“Of course, the Guards should be paying since the delay was of their making,” they said.

I called Ali and asked him to clear the fine.

“No way,” he replied. “Can’t they waive it?”

The intelligence officers apologised again but remained insistent. There were regulations. They couldn’t foot the bill for a mistake of the Guards.

“I’ll settle it,” I said.

But I was out of funds. Iranian banks were about to shut for the weekend so no one in London could send me cash. There was the very real prospect that my departure might be postponed for want of $200. I begged the official to issue the visa and guarantee the cost for two hours while I tried to secure the money. They hesitated, then relented. When it was finally issued, my exit visa was horribly smudged. I managed to make out that I had three more days left.

Money that my office in London had wired a few days earlier arrived just in time. I reached a money-changer as he was closing and he promised to transfer the requisite funds to the immigration police the following day. Then I headed to my hotel to pick up my bags and pay the bill. It was Muharram 5th, the most important night before Ashura. I looked out of the window and thought wistfully of the processions I was missing. I considered staying for the three days I’d been granted. In the end, I didn’t even stop for dinner.

At the airport I forgot both my ticket and passport at the desk. Perhaps I was subconsciously trying to delay the inevitable. Ali was waiting for me on the far side of security, lounging in an armchair, smiling. He told me he was glad it was all over and showered me with apologies. I asked him if I could return to Tehran. “I hope so,” he said. He told me not to forget the Arsenal photo. “Let’s meet again soon, if not in Iran, then in Europe or Iraq.”

“Come for an Arsenal game,” I said, as affectionately as I could. We shook hands. He may even have touched me on my shoulder, before walking away. Then I remembered my notebooks and ran after him. He promised to return them. As he set off again, I remembered my Kindle and dashed off in pursuit once more. Did I really find it so hard to leave him? We shook hands a third time.

This time I watched him walk away for good. In the departure lounge, alone, I listened to businessmen discussing the mediocre offerings in the airport shops. I scanned the upper level to locate the glass-panelled office in which I had been held when I was first arrested, but I couldn’t find it. I wondered if the doctor was looking down. The Qatar Airways flight was parked on the tarmac just as it had been seven weeks earlier. But this time I was level with the gangway that led to it. I produced my passport and ticket, and walked onto the plane.

The air hostess led me to my seat. I wondered if my experience showed on my face, but it turned out that my office had bought me a business-class ticket and this, apparently, was standard treatment. The aeroplane door seemed to be taking too long to shut and I half expected Ali to walk down the gangway with his fellow Guards, smiling, saying that he just had a couple more questions. Even when the plane began to taxi I looked out of the window to make sure that his car wasn’t flagging the aircraft to a halt. Only when the flight map on my seat-back screen showed the plane nosing out of Iranian airspace did I begin to breathe normally. The air hostess appeared with a glass of champagne. I sent a celebratory selfie over Wi-Fi, saluting the office. Another photo pinged back by return. The editors in London were also toasting my safe release.

I remained on Tehran time for weeks after I returned. I would wake at 4am and head to my desk to write, relieved to be able to express myself without fear of leaving a trail for a minder. The intelligence-ministry officials kept calling to inquire about the transfer of the $200, which eventually reached them. But there was silence from Ali. He never dropped off my notebooks at the embassy. And I have yet to send the Arsenal picture.

To the few people who knew what had happened, my wife spoke of her summer of anguish. I felt pressure to show how fearful my captivity had been. “Traumatised hostage”, a friend kept calling me. But I didn’t feel like that. I just wanted to share my photographs of swinging Tehran: the music, the weddings and the warm joyful nights out.■

CORRECTION: A previous version of this article suggested that a woman walking without a veil on the streets of Iran would risk ten years in prison. In fact, the actual punishment would probably be less severe. This has been amended. Sorry.