WASHINGTON (AP) —President Barack Obama went for the defining television shot in Iraq and got it – pictures of hundreds of U.S. troops cheering wildly as he told them it was time for the Iraqis to take charge of their own future.

The war zone photo opportunity produced a stunning show of appreciation for Obama from military men and women who have made great sacrifices, many serving repeated tours in a highly unpopular war.

And the televised outpouring of affection likely will prove critical to the credibility of a new and liberal commander in chief as he tries to sell U.S. warriors and the American public on the grim prospects now facing them in Afghanistan.

Obama has pledged many thousands more U.S. forces for Afghanistan, making good on a campaign promise to intensify the fight against a resurgent Taliban and its al-Qaida allies hiding along the mountainous border with Pakistan.

Even as U.S. troops return from Iraq, many eventually will find themselves headed to Afghanistan. And the peace dividend that accrues with the end of the Iraq war likely will be eaten up by the intensified U.S. effort in a nation known as the graveyard of empires.

The cost of the Afghanistan war will fall to American taxpayers who already have seen hundreds of billions of dollars being spent to save the crippled U.S. financial sector even as they cope with the severest economic recession in more than half a century.

Obama will need all his political finesse to put Americans at ease with spending billions more for a war in a distant land.

Throughout his run for the presidency, Obama set himself apart as a strong opponent of the Iraq war, declaring it had forced the United States to take its eye off the real dangers in Afghanistan, where Osama bin Laden is believed to have plotted the Sept. 11, 2001, terrorist attacks.

The president’s unannounced stop Tuesday in battle-scarred Iraq capped a talky, fencing-mending sojourn through Europe where the new president – warmly received by the European people – sought to plant the seeds of an improved relations with standoffish governments.

But at Baghdad’s Camp Victory assembled U.S. forces mobbed Obama, snapping pictures and stretching out their arms for a handshake with the commander in chief who personally brought the message that they had “performed brilliantly” in a job that was nearly done.

“It is time for us to transition to the Iraqis.  They need to take responsibility for their country,”  Obama told a cheering crowd more reminiscent of adoring campaign supporters than soldiers meeting with their president.

Obama’s journey to Iraq begged the question of why he chose to visit a war that is ending rather than Afghanistan, where the fight promises to drag on for years.

Logistics, more than likely, held sway. Flying in from Istanbul in neighboring Turkey added about a half day to Obama’s absence from Washington. A journey to Afghanistan, far to the east, would have delayed the president’s return for at least a full day. Beyond that, Obama’s team was no doubt banking on a more glowing reception from troops who see the end in sight.

Obama’s reception as the president who is ending the highly unpopular Iraq war could not have contrasted more starkly with the staid, set-piece visits by the conflict’s author, former President George W. Bush.

On his last visit, Bush had to duck as a local journalist threw his shoes at the former president during a news conference with Prime Minister Nouri al-Maliki. The video tape continues to play repeatedly on cable television, interspersed for contrast with Obama working the crowd of 600 troops who assembled for a warmest of welcomes for a president who is sending them home.

EDITOR’S NOTE: Steven R. Hurst, a former Baghdad bureau chief for The Associated Press, has covered foreign affairs for 30 years.

AP Photo/Charles Dharapak. President Barack Obama gestures while speaking to military personnel at Camp Victory in Baghdad, Iraq, Tuesday, April 7.