Image copyright Getty Images Image caption "We invaded Iraq to change the way the greater Middle East works," says Andrew Bacevich. "From that point of view the war is a catastrophic disaster." Above, US troops take cover during a gun fight in Baghdad in August 2003

In September President Barack Obama said, "I was elected to end wars, not start them." Yet ending wars, as he has discovered, can be as hard as waging them.

The former US ambassador to Iraq, James Jeffrey, left Baghdad on a hot day in June 2012. He flew away in a special forces helicopter, as he recalls, and looked down at villas and swimming pools.

"It was quiet and peaceful," he says. He describes his departure as an "emotional" moment - and says that at the time he felt pleased with the outcome of the war.

"We had rescued victory from the jaws of defeat," he says.

Sixteen months later, he is less optimistic. One of the main goals of officials in the White House of George W Bush - the ones who started the war - was to build close ties with forward-looking leaders in the Middle East.

Washington let the field drive it, and didn't ask the big questions Charles Ries, Rand

Today, however, Iraq is besieged by violent factions. And Iraqi Prime Minister Nouri Maliki is known for his authoritarian streak.

"Iraq is not a natural friend of America," says Mr Jeffrey.

These issues were highlighted last week during Mr Maliki's visit to Washington. He apparently asked US officials for military equipment to fight al-Qaeda groups. Iraq has only become more dangerous - and volatile - since the war ended.

The question of why things turned out the way they did, with ongoing violence in Iraq, a rise in militant groups, and a controversial prime minister, is complex.

Lessons for Afghanistan

Image copyright Getty Images Image caption Iraqi police officers are trying to keep the peace in Baghdad

Part of the problem, as authors of a new report from think tank Rand Corporation explain, is how the war was brought to a finish. The war apparently ended in the way it was prosecuted - badly.

The eight-year war, which started in March 2003, cost more than $1 trillion (£623bn). Nearly 4,500 Americans, more than 178 British troops, and tens of thousands of Iraqis died.

The authors of the Rand report say they hope their findings will help officials plan for the next military withdrawal - the Nato mission in Afghanistan ends next year.

For the Rand report, the authors examined the final 15 months of Operation New Dawn, as the post-combat phase of US efforts in Iraq was known, as well as the year following the departure of US troops.

The authors of the report take a close look at the role of Washington officials during this time. A debate over an "enduring presence", as then-US Defence Secretary Leon Panetta described the troops that could remain in Iraq, overshadowed other questions regarding the war.

Many Baghdad officials wanted the troops there - though they found it hard to say so publicly. US officials said the troops would remain only if granted legal immunity. Iraqi officials could not promise that.

In the end the US military personnel - and their equipment - were sent home. The logistics went smoothly, but questions regarding the political handover remained unresolved.

"Washington let the field drive it, and didn't ask the big questions," says one of the report's authors, Charles Ries, who served as the chief economic official in the US embassy during the war.

Washington officials may have shown poor leadership. But so did some generals.

"There's plenty of blame to go around," says Boston University's Andrew Bacevich, the author of Breach of Trust and a critic of the Iraq war.

Responsibility for the debacle should be shared equally by civilian and military leaders, he says: "I'd probably say it's 50-50."

He believes the Iraq war ended badly not because of the reasons that are commonly cited - or not only. The problems ranged from weak civilian leadership to a flawed military strategy.

'Mass, unrelenting violence'

Image copyright Getty Images Image caption Prime Minister Nouri Maliki has reportedly asked US officials for military equipment

In his contribution to the Rand report, for example, Mr Jeffrey is critical of counterinsurgency doctrine and describes nation-building as a "chimera".

These factors contributed to the disastrous end - and violent aftermath. Yet the real problem was not the missteps along the way, says Mr Bacevich, but the way the war was conceived.

"We invaded Iraq to change the way the greater Middle East works - and thereby eliminate the source of anti-American violence in the region," he says. "From that point of view the war is a catastrophic disaster."

In most wars, he says, the conclusion has been disappointing. World War I was known as "the war to end all wars".

The Korean War raged for three years, ending in 1953. Today the two belligerents, North and South Korea, are hardly close. In the Vietnam War 58,000 Americans died.

Mr Bacevich says that the benefits of war rarely outweigh the costs.

"War is ultimately a political act," he says. "We achieved our aims when the enemy surrendered all but unconditionally."

"Conclusive outcomes require unrelenting violence on a very large scale," he says, explaining that the Civil War and World War II illustrate this point. For this reason, he says, political leaders should consider what they are getting themselves into - before they start a war.

"Conclusions tend to be messy, and for that reason statesmen should be wary when people tell them that going to war will solve our problems," he says. "It may, but it may not."

As Mr Jeffrey says, large-scale change is difficult, and so is winning over a local population.

"Those hearts-and-minds things," he says, "they don't work."