The man with the thin face and stripy blue shirt sat down next to me on the bench. "Welcome to Iran," he said. I might have felt more welcome if his colleagues hadn't arrested me half an hour earlier. We were at an anonymous central Tehran building occupied by the Basij, the religious police, who were busy detaining journalists that evening.
The Channel 4 News team - cameraman, producer, local fixer and myself - had gone to Imam Hossein Square, where a small bomb placed in a rubbish bin had killed two people. Before we even picked up our camera, a pack of youths surrounded us and started shouting. In most countries, you might think these were hoodlums, but in Iran groups of young men sporting dark stubble, wearing jeans and with mobile-phone remotes dangling from their ears are usually policemen. Such was the confusion that, as we were hustled into a vehicle, it took me some time to understand that the man driving was also a journalist under arrest: local reporters are detained so frequently in Iran that they know it's better to go in their own cars so they can get home easily. A Basiji sat in the back to guide us to the headquarters.
We were ushered through a muddy courtyard full of motorbikes, up a concrete staircase and into a white-walled room covered in posters of the late Ayatollah Khomeini and the current supreme leader, Ayatollah Khamenei. The young Basiji who wanted me to feel welcome asked if I spoke French. "Je suis inspecteur de police," he explained, in case I hadn't guessed.
Every few minutes another journalist was brought in, until we had enough for a party. Unfortunately, after half an hour, someone remembered that in the Islamic Republic of Iran unrelated men and women aren't meant to mix, so the females were ushered into a separate room. Sweet cordials in lurid colours were proffered, and a Basiji came round with a tray of almond-stuffed dates. It emerged that one of the women detained with us was not a journalist but a famous Iranian actress. Swathed in a white headscarf, she sat in the airless office looking sultry.
"Isn't this a lucky evening for you?" an Iranian reporter teased the Basiji charged with keeping the women detainees in order. "Bet you never thought you'd get to arrest someone as beautiful as her!" The Basiji shuffled awkwardly and looked down at the papers he was pretending to study. I never did understand why the actress had been picked up. After two hours, at around 1.30am, we were released. Our fixer had called a man from the Ministry of Culture and Islamic Guidance, who had called a man from the Foreign Ministry, who was despatched to liberate the foreign press corps. The latter apologised repeatedly as he walked us to the car.
A few days later, as the first round of Iran's presidential campaign reached its climax, we followed the reformist candidate Mostafa Moin to Quchan in the north-eastern province of Khorasan. I should have read the signals. While we were filming Moin's rally in the small, cheerless town near the border with Turkmenistan, a smiling man with a stubble-covered chin approached and uttered the fateful words "welcome to Quchan".
After a few minutes he demanded our filming permit, which we duly presented. He refused to give it back. I interviewed some students, and a small crowd formed - the Basiji's cue to ask us to accompany him to his office nearby. This time we stayed in the car, leaving the driver and fixer to argue the point. A few phone calls to the Ministry of Culture in Tehran and we were on our way; the Basiji had exercised his power, by ensuring that we filmed no more in Quchan, and the ministry had asserted its own by persuading him to let us go.
The significance of these encounters is not that press freedom was curtailed (although, of course, it was), but that they illustrate the power struggle that prevents Iran from moving forward. The country has two governments - an outward-looking one that had invited us to cover the election, and an ideological one that suspects foreign journalists are infidel spies. The two operate in parallel; but on occasion the rails converge and a crash occurs - hence our arrest by the agents of one government and our liberation by those of the other.
Recognising the continued power of the Basij and other religious security forces may be the key to understanding not just the result of the first round in Iran's elections, but also the contradictory forces governing today. Everyone predicted correctly that the wily millionaire cleric Hashemi Rafsanjani, known as "the Old Fox", would gain the most votes. But no one forecast that the hardline mayor of Tehran, Mahmoud Ahmadinejad, a Basij instructor and former Revolutionary Guard commander, would be the one to force Rafsanjani into a run-off.
Journalists and pollsters predicted that a reformist candidate, or one who campaigned with modern marketing methods, would come second. Moin - the Al Gore of Iranian politics, with the same solid intellect, worthy manner and lack of charisma - was favoured for the run-off, because he claimed the mantle of the popular current president Mohammad Khatami, who has pushed hard for political reform and social liberalisation. Even Iranian commentators misunderstand Iran today.
While other candidates spent millions of rials on merchandising and slick advertising, Ahmadinejad operated beneath the surface. His only TV ad showed his modest home, and emphasised his refusal to draw a salary from City Hall. His message went out through the mosques. The clerical elite let it be known to its network across the country that Ahmadinejad was the one. The security forces, including the Basij and the Revolutionary Guard, and their families, all voted for him. On his website, he writes: "In the name of God, I am proud to have been a teacher of the Basij, and I pray to God that I continue to be one."
Most candidates tried to appeal to the huge block of voters under 25, promising less interference in people's private lives. By contrast, as mayor of Tehran, Ahmadinejad has turned theatres into prayer rooms and proposed digging up the martyrs from the Iran-Iraq war to re-bury them in shrines on the capital's squares and roundabouts. He even tried to ban David Beckham's image on advertising billboards, on the grounds that it was "un-Islamic". But that wasn't necessarily why people voted for him. His masterstroke was to understand that Iran's vast, impoverished masses of unemployed young men have more pressing matters on their minds than how far back their sisters can push their headscarves.
Ahmadinejad appealed to the poor, saying he would provide jobs and money. He has repaved potholed roads in Tehran and given interest-free loans of ten million rials (£600) to newly married couples. He has forgiven debts owed to the city council and created the image of an honest man who understands the working class. The son of a blacksmith, he once wore a dustman's uniform to a meeting of municipal workers as a sign of solidarity.
"Rafsanjani is for the rich. Moin is for intellectuals. But Ahmadinejad is one of us," said a supporter. "He is a pure man, an honest man," said another.
Ahmadinejad's desire to create "a perfect Islamic state" may have appealed to the Basij, who are deeply motivated by religion; but they are also drawn from impoverished families, so his identification with the poor may have been a more important factor.
Iranians have not turned against social reform. The man who narrowly came third, Mehdi Karroubi, called for a less restrictive interpretation of Islam. And yet, what garnered him votes was a promise to give £35 cash monthly to every adult. Ahmadinejad got more or less the same number of votes as the conservative candidate who stood against Khatami in 2001, but this time there was no single reformist candidate to unite behind.
The lesson of the Iranian election is that we look at the country through a distorting lens. The US sees only the threat of Iran's nuclear programme. Europe has focused mainly on the desire of many Iranians for a more democratic system of government, an end to human rights abuse and more social freedoms. But the message voters have delivered is that poverty is the issue that first needs attention.
Iran's economy floats only because of high oil prices. Inflation runs at about 20 per cent, and most Iranians have a lower standard of living than during the 1970s under the Shah. Business remains in the hands of the bonyads, foundations linked to clerics, which run anything from charities to factories. Limited privatisation has benefited those with good connections, not the poor. Iran has started negotiations to join the World Trade Organisation, but while this may wrench some parts of the economy into the global system, it will probably make things worse for the poor in the short term, as badly run state-sponsored industries will collapse if they are exposed to international competition. A long-awaited trade deal with the EU is on hold until some form of compromise can be reached on the nuclear issue. Rafsanjani claimed during the campaign that he could square this circle, but it is hard to see how. US sanctions against Iran are unlikely to be lifted until the Islamic Republic abandons its basic tenets, which means a second revolution.
Despite condemning him as corrupt and too close to the clerical elite, nearly all reformist groups have come out for Rafsanjani. It is not unlike the 2002 French election when, after the elimination of the Socialist Lionel Jospin, voters had to choose between Jacques Chirac and Jean-Marie Le Pen. "Hold your nose and vote for Rafsanjani," said Emadeddin Baghi, head of the Association for Defending Prisoners' Rights. "We have to select between the bad and the worst."
Next time I go to Iran, I plan to spend more time with unemployed labourers in the sprawling suburbs of south Tehran, and less with rich kids in the north of the city, who get their ideas from the internet and satellite TV. Poverty is a less compelling story than the desire to throw off the veil, but maybe it's more important. That assumes I do return. If Ahmadinejad were to become president, the Basij would have less trouble with foreign journalists, as the government would be unlikely to allow such suspicious people into the country in the first place.