— More than three years after he campaigned against the Iraq war near this Army post, President Obama returned Wednesday to hail the hundreds of thousands of U.S. troops who fought to establish the “sovereign, stable and self-reliant Iraq” that America is leaving behind this month.

With his wife, Michelle, by his side, Obama marked the United States’ imminent departure from Iraq by telling hundreds of service members, many clad in fatigues and maroon berets signifying active airborne status, that the war was a “source of great controversy” at home. As a U.S. senator, Obama opposed the decision to invade Iraq and railed against the conflict in a 2008 campaign speech in nearby Fayetteville.

But he stressed Wednesday that those who fought, as well as their families, will always be remembered and honored for their service.

“So, as your commander in chief, and on behalf of a grateful nation, I’m proud to finally say these two words, and I know your families agree — welcome home!” Obama said to the crowd of 3,000 as a giant American flag hung behind him at the 440th Structural Maintenance Hangar here.

The president’s speech capped a week of events leading to the milestone when the final U.S. troops cross the border out of Iraq by the end of the month. Obama tallied the costs of the extended battle that toppled the regime of President Saddam Hussein: More than 1.5 million U.S. troops served; 30,000 were wounded and 4,500 died, including 202 from Fort Bragg.

The effort was not in vain, Obama declared, despite security challenges that will persist after the U.S. departure. The president met with Iraqi Prime Minister Nouri al-Maliki on Monday at the White House to discuss postwar cooperation as Iran’s creeping influence in the Middle East worries U.S. policymakers.

“Of course, Iraq is not a perfect place,” Obama acknowledged Wednesday. “But we are leaving behind a sovereign, stable and self-reliant Iraq, with a representative government that was elected by its people. We are building a new partnership between our nations.”

Before addressing the troops, the Obamas met with the family of an infantryman from Fort Bragg who was killed Nov. 14 when a makeshift bomb hit his convoy in Iraq.

Obama’s appearance was also intended to boost his political standing as he ramps up his 2012 reelection effort.

Though the end of the war meets a timeline that was negotiated by Obama’s predecessor, George W. Bush, the White House has portrayed the milestone as a promise kept by the president. On March 19, 2008 — the fifth anniversary of the war — then-Sen. Obama of Illinois traveled to Fayetteville to give a campaign speech pledging to end the conflict; he capped that appearance with a game of pickup basketball with troops.

“The war in Iraq has done more to embolden America’s enemies than any strategic choice that we have made in decades,” Obama said then. “I will offer a clean break from the failed policies and politics of the past.”

The president’s political opponents have criticized him for his decision to remove the troops after he and Maliki failed to agree in October on a pact to leave some U.S. forces in the country for training and security.

Republican presidential candidate Mitt Romney , who has savaged Obama’s foreign policy as weak, suggested that pulling out U.S. forces would increase the chance that Iraq’s fledgling government would become engulfed in chaos.

Obama’s “astonishing failure to secure an orderly transition in Iraq has unnecessarily put at risk the victories that were won through the blood and sacrifice of thousands of American men and women,” Romney said.

At Fort Bragg, the president told the troops: “You remind us that there’s nothing that we Americans can’t do when we stick together. For all of the disagreements that we face, you remind us that there is something bigger than our differences that makes us one nation, one people. . . . You can’t afford to forget that. If you forget, somebody dies, a mission fails. So you don’t forget. You have each other’s backs.”

He alluded obliquely to the hyper-partisanship and bitter gridlock that have come to define Washington politics.

Obama pledged in his remarks that his administration will help tens of thousands of troops find jobs after they transition out of the military over the coming years.

The unemployment rate for military veterans is higher than the overall rate, and the administration has made hiring veterans a key element of its jobs plan. The only piece of Obama’s $450 billion American Jobs Act that Congress has approved is a tax cut for businesses that hire veterans of Iraq and Afghanistan.

“You stood up for America; now America must stand up for you,” Obama told the troops. “Our commitment to you doesn’t end when you take off the uniform.”

The troops were buoyed by the president’s appearance, whooping in a military cheer several times.

In the audience, Staff Sgt. Ketorrin Edwards, 27, of Angleton, Tex., said he hoped that the politics surrounding the war will not overshadow the sacrifices made by those who served.

“With so many losses that we’ve taken and all the hard work and sacrifice these soldiers and their families have put forward, I would hope that it would not go unrealized and that people do not take it lightly,” said Edwards, who worked in a maintenance unit during a stint at Forward Operating Base Speicher near Tikrit from 2005 to 2006.

Staff Sgt. Dartanyon Williams, 36, of Fort Lauderdale, Fla., said that “history will show whether our sacrifices were in vain or whether it will bring about a better tomorrow.”