There is no city like Najaf, which stands on the edge of the desert a few miles west of the Euphrates in Iraq. It was in nearby Kufa in 661 that Imam Ali, the son-in-law and cousin of the Prophet Mohamed, was badly wounded by an assassin and, as he lay dying, instructed his followers to strap his body to the back of a white camel and, where the camel stopped, to dig his grave. On this spot grew up the shrine city of Najaf, a place of pilgrimage for the Shia and home to many of their leaders, such as Grand Ayatollah Ali Sistani.

In other religions, believers venerate martyrs who died many centuries ago, but Iraqi Shi'ism is unique because so many of its martyrs have been killed in the past 40 years. There is Mohammed Baqir al-Sadr, revolutionary theologian and opponent of Saddam Hussein, who had him executed in 1980. In 1991, Shia rebels seized the city, and were slaughtered when it was retaken by Saddam's tanks. Later in the 1990s, Mohammed Sadiq al-Sadr created the Sadrist movement with its potent mix of revivalist religion, nationalism and social and political activism, before he was shot dead, with two of his sons, by killers sent by Saddam. In 2004, Muqtada al-Sadr and the Mehdi Army battled the US army street by street for control of the city.

The blood has not stopped flowing. I visited the shrine of Imam Ali, passing through the outer gate with its entrancing tiles of green, blue and yellow, then walking through the courtyard to the shrine's inner doorway of beaten gold. I was standing with a crowd of pilgrims pressing their hands or banners to the grating around Imam Ali's tomb when I was pushed aside by men bearing a wooden coffin under an embroidered cloth. Somebody whispered that it was the body of one of the 200 or more Shia killed by al-Qa'ida bombs over the previous week. It was being taken, as is the custom, through the shrine before being buried in the vast Wadi al-Salaam cemetery.

Download the new Independent Premium app Sharing the full story, not just the headlines

A crucial question for the future of Iraq is the degree to which the Shia will retaliate against the Sunni for killings primarily directed against Shia civilians. The last time this happened, in 2006, Shia revenge attacks turned into a pogrom of Sunni in Baghdad, as a result of which survivors fled or were forced into enclaves that are today vulnerable to renewed Shia attacks. On the other hand, the Iraqi government is stronger than it was and the Shia religious leaders do not want a sectarian war.

Najaf has again become a great centre of religious learning. Sheikh Mahmoud al-Jayashee, a member of the Hawza, a Shia seminary, told me that there are between 30,000 and 40,000 religious students here, compared with about 800 in 1990, when Saddam Hussein limited numbers by conscripting Iraqi students and denying visas to foreigners. He confirmed that teachers and students in the Hawza remain deeply divided between the political and social activism of the Sadrists and the larger part of clergy who believe religion should focus purely on the spiritual. There is also resentment against the Sadrists for provoking a destructive battle with the Americans in Najaf in 2004.

The Shia have coped bravely with oppression and persecution down the centuries but their record in wielding power has been much less creditable. Sheikh Mahmoud agreed that the giant construction project at the west end of the shrine – two storeys above ground and three below – was out of keeping with the poverty of so many in Najaf. The pilgrims bring money and the city is richer and safer than many in Iraq, but some 40 per cent of its people still live in poverty, their shabby clothes showing that they barely scrape a living as day labourers in construction and agriculture.

The Shia takeover of the state has not brought better government. I was visiting the flood-stricken area west of Najaf where a four-day downpour earlier this month led to roads, houses and entire villages being swept away. Nobody was doing much to help survivors aside from the Red Crescent and the Sadrists. But, right in the middle of the newly created swamps, we came across the middle section of an enormous bridge standing on concrete columns. I thought at first that the force of the flood water might have broken off the sections at either end. But, examined more closely, it became clear that the bridge had never been finished, but stood looking like a colossal symbol of Iraqi governments' liking for immense, expensive and useless projects while people lack clothes, food and shelter.

There is more to Najaf than blood and poverty. I was being guided by Sayid Sa'ad Aziz al-Hilli al-Moussawi, a shopkeeper and community leader, in a working-class neighbourhood called Jadaid al-Rabiya, built on an escarpment from which one could see "the Sea of Najaf", a large lake swollen by the floods. Mr Moussawi said he had fought US troops in 2004, but the battle that really excited him was one that had happened more than 1,300 years earlier, when Imam Hussein and his brother Abbas had been killed in the Battle of Karbala in 680: the central religious drama of the Shia faith. Every year, Mr Moussawi helps organise a play – rather like a Christian passion play – which is a full scale re-enactment of the battle. He said he did not care how much money he spent buying props, while people in his district somehow collected 20 to 40 horses for riders on opposing sides.

Mr Moussawi took us to a small pond with rubbish floating in it; in the play, it represents the Euphrates to which Imam Abbas went to get water for the thirsty women and children of their besieged camp. Detected on his return with a water skin, Abbas fought until his arms were cut off as he stood with his back to a palm tree where he was battered to death. Mr Moussawi showed the palm tree they used for Abbas's last stand, adding that they erected real tents for the play then set fire to them. He said proudly that the re-enactment last month was watched by 50,000 people. In Najaf there is a sense that what happened 1,300 years ago and what happens today have blended together and it is this that gives the city its magical quality.