On 14 June, this year an interpreter for the US army called Hameed al-Daraji was shot dead as he was sleeping in his house in Samarra, a city 60 miles north of Baghdad.

In some respects there was nothing strange about the killing, since 26 Iraqi civilians were murdered in different parts of the country on the same day. As well as working periodically for the Americans since 2003, Mr Daraji may have recently converted to Christianity and unwisely taken to wearing a crucifix around his neck - a gesture quite enough to make him a target in the Sunni Arab heartlands.

What made Iraqis, inured to violence though they are, pay particular attention to the murder of Mr Daraji was the identity of his killer. Arrested soon after the body was discovered, his son is reported to have confessed to his father's murder, explaining that his father's job and change of religion brought such shame on the family that there was no alternative to shooting him. A second son and Mr Daraji's nephew are also wanted for the killing and all three of the young men are alleged to have links to al-Qa'ida.

The story illustrates the degree to which Iraq remains an extraordinarily violent place. Without the rest of the world paying much attention, some 160 Iraqis have been killed, and hundreds wounded, over the past two weeks. Civilian casualties in Iraq are still higher than in Afghanistan, though these days the latter has a near-monopoly of media attention. But the killing of Mr Daraji should give pause to those who imagine that the US occupation of Iraq somehow came right in its final years, and that American combat troops might even care to linger on in Iraq beyond their scheduled departure date in six weeks' time on 31 August. All remaining US troops are to be out at the end of 2011 under a Status of Forces Agreement signed by President Bush in 2008 during his last days at the White House.

American troops will leave behind a country that is a barely floating wreck. Baghdad feels like a city under military occupation, with horrendous traffic jams caused by the 1,500 checkpoints and streets blocked off by miles of concrete blast walls that strangle communications within the city. The situation in Iraq is in many ways "better" than it was, but it could hardly be anything else, given that killings at their peak in 2006-2007 were running at about 3,000 a month. That said, Baghdad remains one of the most dangerous cities in the world, riskier to walk around than Kabul or Kandahar.

Not everything can be blamed on the present political leadership. Iraq is recovering from 30 years of dictatorship, war and sanctions, and the recovery is grindingly slow and incomplete because the impact of the multiple disasters to strike Iraq after 1980 was so great. Saddam Hussein poured money into his self-inflicted war with Iran, leaving nothing for hospitals or schools. Defeat by the US-led coalition in Kuwait provoked a collapse in the currency and 13 years of UN sanctions that amounted to an economic siege. Iraq has never recovered from these catastrophes. When the UN tried to arrange the replacement of equipment at the power stations and water-treatment plants in the 1990s, the original manufacturers said the plant was so antique that spare parts were no longer manufactured.

During sanctions, the government had no money and ceased to pay its officials, who therefore charged for their services. These days, they receive good salaries but the old tradition of doing nothing without a bribe has not died away. Saturation levels of corruption render the state dysfunctional. To give a small example: one friend teaching at a university in Baghdad became pregnant and applied for a month's paid leave to have her baby, as was her right. The university administrators said she could only have the leave, but on condition that she handed over the month's salary to them. What makes corruption in Iraq so devastating in its effects is that it cripples the state apparatus and prevents it performing its most essential functions. In 2004-2005, for instance, the entire military procurement budget of $1.2bn (£787m) was stolen, though this may have been explained by the chaos of the first years of the post-Saddam Iraqi state, with the Americans calling many of the shots and nobody sure who really held power.

Five years later, would be reasonable to suppose that military procurement had improved, especially when it comes to essential pieces of equipment for the security forces. Here, there is no greater priority for the government than stopping al-Qa'ida suicide bombers driving vehicles packed with explosives into central Baghdad and blowing themselves up outside government ministries, killing and wounding hundreds of people.

Iraqis often ask why these bombers are able to pass unsuspected through so many checkpoints. Over the past year, it has become clear that there is an appallingly simple reason for this that explains much about the weakness of the Iraqi state machine. The extraordinary truth is that keeping bombers out of Baghdad is, to say the least, undermined because the main bomb-detecting device used by troops and police to find explosives is a proven fake. The government paid large sums for the detector, called a "sonar" by Iraqis, though it comes without a power source - and supposedly receives this from the man holding it, who is meant to shuffle his feet to generate static electricity.

Useless though it is, the "sonar", a black plastic grip with a silver-coloured wand like a television aerial sticking out the front, is the main method by which suspect vehicles in Baghdad are checked by soldiers and police. If arms or explosives are present, the wand is meant to incline towards them, operating in the same way as a water diviner's rod.

What is striking about the bomb detector, officially known as the ADE-651, is that it has been repeatedly exposed as useless by government experts, newspapers and television. It was originally produced in Britain, on a disused milk farm in Somerset, but the managing director of the company behind it was arrested in the UK on suspicion of fraud and its export has now been banned. The only electronic component in the device is a small disk, worth a few pennies, similar to that attached to clothes in high-street shops to stop people walking away with them without paying.

Though each "sonar" costs only about $50 to make, Iraq spent $85m buying the bomb detectors in 2008 and 2009. Despite being exposed as worthless, they have never been withdrawn and remain the main device for detecting al-Qa'ida bombers before they reach their target. An Iraqi police chief told me privately that the police know their detectors do not work but go on using them because they are ordered to do so. The presumption in Baghdad is that somebody was paid a large bribe to buy the "sonars" and does not want to admit they are junk. Unsurprisingly, bombs which explode with devastating effect in the heart of the capital turn out to have passed through a dozen checkpoints undetected.

Corruption explains much in Iraq - but it is not the only reason why it has been so difficult to create a functioning government. Saddam Hussein should not be a hard act to follow. Part of the problem here is that the US invasion and the overthrow of Saddam Hussein had revolutionary consequences because it shifted power from the Sunni Arab Baathists to the 60 per cent of Iraqis who are Shia and in alliance with the Kurds. Iraq had a new ruling class rooted in the rural Shia population and headed by former exiles with no experience of running anything. In many ways, their idea of government is to recreate Saddam's system, only this time with the Shia in charge. It used to be said that Iraq was under the thumb of Sunni Arabs from Tikrit, Saddam Hussein's home city north of Baghdad. These days people in Baghdad complain that a similar tight-knit gang from the Shia city of Nasiriyah surrounds the Prime Minister Nouri al-Maliki.

In many ways, Iraq is becoming like Lebanon, its politics and society irredeemably divided by sectarian and communal loyalties. The outcome of the parliamentary election on 7 March could easily be forecast by assuming that most Iraqis would vote as Sunni, Shia or Kurds. Jobs at the top of government and throughout the bureaucracy are filled unofficially according to sectarian affiliation. In a crude way, this does give everybody a share of the cake, but the cake is too small to satisfy more than a fraction of Iraqis. Government is also weakened because ministers are representatives of some party, faction or community and cannot be dismissed because they are crooked or incompetent.

Going back to Baghdad last month, after being away for some time, I was struck by how little had changed. The airport was still among the worst in the world. When I wanted to fly to Basra, Iraq's second biggest city and the centre of the oil industry, Iraqi Airways said they had only one flight during the week and they were none too certain when that would leave.

Violence may be down, but few of the 2 million Iraqi refugees in Jordan and Syria think it safe enough to go home. A further 1.5 million people are Internally Displaced Persons (IDPs), forced out of their homes by sectarian pogroms in 2006 and 2007 and too frightened to return. Of these, some half a million people try to survive in squatter camps which Refugees International describes as lacking "basic services, including water, sanitation and electricity, and built on precarious places - under bridges, alongside railroad tracks and amongst garbage tracks". A worrying fact about these camps is that the number of people in them should be shrinking as sectarian warfare ebbs, but in fact the IDP population is growing. These days refugees come to the camps not because of fear of the death squads but because of poverty, joblessness and the prolonged drought which is driving farmers off their land.

Iraq is full of people who have little left to lose and have a deep anger towards a government which they see as being run by a kleptomaniac elite gobbling up Iraq's oil revenues. As in Lebanon and Afghanistan, where disparities in wealth are also huge, class hatred and religious differences combine to exacerbate the hatred felt between and within communities. The anger of the dispossessed explains the savagery of the looting of Baghdad in 2003, as people poured out of the slums of Sadr City to plunder government ministries and offices.

Iraq differs from Lebanon in one crucial respect. It is an oil state with annual revenues of $60bn last year and with unexploited oil reserves among the largest in the world. Its oil exports may quadruple over the next decade under contracts signed with international oil companies last year. There ought to be enough money to raise standards of living and rebuild the infrastructure after long neglect.

At first sight, oil could be the solution to Iraq's innumerable problems; but in Iraq in the past, and in other oil states, it has proved a political curse as well as an economic blessing. Countries reliant on oil and gas exports are almost invariably dictatorships or monarchies. Control of oil revenues, not popular support, appears to rulers to be the source of their power. If there is opposition, then oil wealth enables leaders to build up and pay for security forces to crush it.