BAGHDAD — The United States military officially declared an end to its mission in Iraq on Thursday even as violence continues to plague the country and the Muslim world remains distrustful of American power.
In a fortified concrete courtyard at the airport in Baghdad, Defense Secretary Leon E. Panetta thanked the more than one million American service members who have served in Iraq for “the remarkable progress” made over the past nine years but acknowledged the severe challenges that face the struggling democracy.
“Let me be clear: Iraq will be tested in the days ahead — by terrorism, and by those who would seek to divide, by economic and social issues, by the demands of democracy itself,” Mr. Panetta said. “Challenges remain, but the U.S. will be there to stand by the Iraqi people as they navigate those challenges to build a stronger and more prosperous nation.”
The muted ceremony stood in contrast to the start of the war in 2003 when an America both frightened and emboldened by the attacks of Sept. 11, 2001, sent columns of tanks north from Kuwait to overthrow Saddam Hussein.
As of last Friday, the war in Iraq had claimed 4,487 American lives, with another 32,226 Americans wounded in action, according to Pentagon statistics.
The tenor of the 45-minute farewell ceremony, officially called "Casing the Colors,” was likely to sound an uncertain trumpet for a war that was started to rid Iraq of weapons of mass destruction it did not have. It now ends without the sizable, enduring American military presence for which many officers had hoped.
Although Thursday's ceremony marked the end of the war, the military still has two bases in Iraq and roughly 4,000 troops, including several hundred who attended the ceremony. At the height of the war in 2007, there were 505 bases and more than 170,000 troops.
According to military officials, the remaining troops are still being attacked on a daily basis, mainly by indirect fire attacks on the bases and road side bomb explosions against convoys heading south through Iraq to bases in Kuwait.
Even after the last two bases are closed and the final American combat troops withdraw from Iraq by Dec. 31, under rules of an agreement with the government in Baghdad, a few hundred military personnel and Pentagon civilians will remain, working within the American Embassy as part of an Office of Security Cooperation to assist in arms sales and training.
But negotiations could resume next year on whether additional American military personnel can return to further assist their Iraqi counterparts.
Senior American military officers have made no secret that they see crucial gaps in Iraq's ability to defend its sovereign soil and even to secure its oil platforms offshore in the Persian Gulf. Air defenses are seen as a critical gap in Iraqi capabilities, but American military officers also see significant shortcomings in Iraq's ability to sustain a military, whether moving food and fuel or servicing the armored vehicles it is inheriting from Americans or the fighter jets it is buying, and has shortfalls in military engineers, artillery and intelligence, as well.
The tenuous security atmosphere in Iraq was underscored by helicopters that hovered over the ceremony, scanning the ground for rocket attacks. Although there is far less violence across Iraq than at the height of the sectarian conflict in 2006 and 2007, there are bombings on a nearly daily basis and Americans remain a target of Shiite militants.
Mr. Panetta acknowledged that “the cost was high — in blood and treasure of the United States, and also for the Iraqi people. But those lives have not been lost in vain — they gave birth to an independent, free and sovereign Iraq.”
The war was started by the Bush administration in March 2003 on arguments that Iraq had weapons of mass destruction and had ties to Al Qaeda that might grow to an alliance threatening the United States with a mass-casualty terrorist attack.
As the absence of unconventional weapons proved a humiliation for the administration and the intelligence community, the war effort was reframed as being about bringing democracy to the Middle East.
And, indeed, there was euphoria among many Iraqis at an American-led invasion that toppled Saddam Hussein. But the support soon soured amid a growing sense of heavy-handed occupation fueled by the unleashing of bloody sectarian and religious rivalries. The American presence also proved a magnet for militant fighters and an Al Qaeda-affiliated group took root among the Sunni minority population in Iraq.
While the terrorist group has been rendered ineffective by a punishing series of Special Operations raids that decapitated the organization, intelligence specialists fear that it is in resurgence. The American military presence in Iraq, viewed as an occupation across the Muslim world, also hampered Washington's ability to cast a narrative from the United States in support of the Arab Spring uprisings this year.
Even handing bases over to the Iraqi government over recent months proved vexing for the military. In the spring, commanders halted large formal ceremonies with Iraqi officials for base closings because insurgents were using the events as opportunities to attack troops. “We were having ceremonies and announcing it publicly and having a little formal process but a couple of days before the base was to close we would start to receive significant indirect fire attacks on the location,” said Col. Barry Johnson, a spokesman for the military in Iraq. “We were suffering attacks so we stopped.”
Across the country, the closing of bases has been marked by a quiet closed-door meeting where American and Iraqi military officials signed documents that legally gave the Iraqis control of the bases, exchanged handshakes and turned over keys.
The chairman of the Joint Chiefs of Staff, Gen. Martin E. Dempsey of the Army, has served two command tours in Iraq since the invasion in 2003, and he noted during the ceremony that the next time he comes to Iraq he will have to be invited.
“I kind of like that, to tell you the truth,” General Dempsey said.
The last convoy of US soldiers crosses the border from Iraq into Kuwait, ending the eight-year long Iraq War. 
The last convoy of US soldiers crossed the border from Iraq into Kuwait on Sunday, effectively bringing the controversial eight-year long Iraq War to an end. The final convoy, containing around a hundred US military vehicles with five hundred troops, exited Iraq at 0738  (0438 ) Sunday.

Private First Class Martin Lamb described the departure as "a good feeling ... knowing this is going to be the last mission out of here". The event was "part of history, you know — we're the last ones out," according to Lamb.

The Iraq War, which commenced in 2003 on the pretext of Iraq possessing , which later turned out to be false, was responsible for toppling the regime of Iraqi dictator Saddam Hussein and introducing a democratic government within Iraq. In the aftermath of Hussein's downfall, a violent, religion-based conflict broke out between those of  faith and  communities, reaching its peak in 2006. The following year, a large number of US troops were sent into Iraq; the number of sectarian and insurgent attacks subsequently declined.

The Iraq War involved a maximum of over 170,000 US troops, stationed in Iraq at more than 500 bases. Tens of thousands to over 100,000 Iraqi citizens and close to 4,500 US troops were killed as a result of the war. The financial cost of the Iraq War was almost 1 trillion (767 billion or 638 billion) to the .

US presence in Iraq has been reduced to 157 soldiers in charge of military training at  and a minor base of US marines. The US federal government reportedly intended to retain a minor counter-terrorism presence in Iraq, as well as the continuation of military training in the country. However, negotiations between US government representatives and Iraqi officials were unsuccessful, as they failed to reach an agreement on legal matters, such as troop immunity.

In 2008, the  had committed to withdrawing all US troops from Iraq by the end of 2011, a movement which was announced by his successor and current US president Barack Obama in October 2011. Obama signified the conclusion of the war with Nouri al-Maliki, the prime minister of Iraq, earlier this month. In a speech in North Carolina at , Obama stated that the country US troops were leaving is now "sovereign, stable and self-reliant".

US and Kuwaiti soldiers close the gate between Kuwait and Iraq, after the last military convoys passed through, signaling the end of the Iraq War. 
Reaction to the US government's decision has been mixed. According to '''' opinion polls in the United States indicate that a majority of Americans believe the war lasted longer than it should have done. Obama himself had opposed the war when he ran for president and vowed to end it. News agencies report Iraqis glad to see the US leave, but concerned for the future.

'''' reports that Iraqis also have mixed feelings, such as Safa, a 26-year old baker using a pseudonym, who said "I am proud — all Iraqis should be proud, like all those whose country has been freed. The Americans toppled Saddam, but our lives since then have gone backward." He also said, "The situation will only improve if politicians work on fighting corruption and adopt reforms."

A 50-year-old mother calling herself Umm Mohammed said, "I don't think we can ever forgive the Americans for what they did to us, from killings to terrorism. Those people Americans think only about themselves, and not about the consequences of their actions."

Mohammed Abdelamir, 60, said "We must all cooperate and work to improve the economy, the society, and begin rebuilding, and not fight because we are seeing that some politicians have already begun putting a stick in the wheel."

Other Iraqis who worked for Americans are fearful over their departure, fearing they may be killed. John, a pseudonym for one such Iraqi, said to ''Al-Jazeera'', "It’s a fact to these people, we betrayed our country, anyone who worked with the Americans. They think we don’t even deserve to be Iraqi."

Mark, another such Iraqi, said "All the people around me know that I was working with the Americans. We feel that we are in danger from anyone who was against the US troops." John and Mark both worked for  (PRT) in Iraq. Both men have applied for Special Immigrant Visas (SIV) which the US government created in 2008 for Iraqis who have worked for US forces.

However, there is an immense backlog for applicants, as over 30,000 await a decision. So far, only 7,000 SIV visas have been issued. John has been waiting for a visa for over a year, Mark has been waiting nine months since applying in March. Mark said, "They said we should wait at least six months, but this is crazy". And, "For nine months I am jobless, waiting for that visa. I have nothing to do."