Kabul, Afghanistan (CNN) -- Gen. David Petraeus, the outgoing top commander of the NATO forces in Afghanistan, formally transferred authority Monday to incoming commander Marine Corps Gen. John Allen.
Several senior Afghan and NATO officials, including U.S. Chairman of the Joint Chiefs of Staff Adm. Mike Mullen, attended the change-of-command ceremony in Kabul.
"Throughout, we will keep our eyes on the horizon -- the future of Afghanistan, " Allen told the audience, " a nation of free people at peace, governed under its constitution, pursuing economic enterprise and development, in a secure and stable environment free from the extremism and terrorism that has plagued this wonderful country and its people for more than a generation.
In the end -- together we will prevail."
He inherits a force that is coming under renewed attack just as NATO prepares to begin the first phase of handing over provincial security to Afghan security forces.
On Monday, three service members with the NATO-led International Security Assistance Force were killed in a blast in eastern Afghanistan.
Their deaths bring to 34 the number of international troops who have died in Afghanistan in July..
Since the start of this year, 314 coalition soldiers have died in the country.
For his part, Petraeus plans to retire from the Army at the end of August and assume the CIA director's job September 6.
"I wanted this job," Petraeus, 58, said at his Senate confirmation hearing. "I am taking off the uniform I have worn for 37 years to do this the right way."
Dubbed King David for turning around what seemed like a losing battle as top U.S. commander in Iraq before he went to Afghanistan, Petraeus is considered a top general in his era, with Esquire magazine naming him one of the most influential people of the 21st century.
He took over in Afghanistan on July 4 last year unexpectedly after a Rolling Stone magazine article prompted the resignation of Gen. Stanley McChrystal.
"We've jokingly said that I went to the White House for the monthly National Security Council meeting on Afghanistan and Pakistan with President Obama, and came out with a new job," Petraeus said. "And that's not far from the truth."
The U.S. military is losing the architect of modern-day counterinsurgency operations.
Petraeus wrote his doctorate dissertation on the lessons America learned in Vietnam.
Later, he devised the Army/Marine field manual, challenging the military to think differently about how it relates to the civilian population in dealing with a bloody insurgency.
This week, ahead of his departure, Petraeus assessed the results of his strategy in Afghanistan.
"What we have done is implement the so-called NATO comprehensive approach, a civil-military campaign ... that does indeed embody many of the principles of the counterinsurgency field manual that we developed back in 2006, and which we employed in Iraq in the surge of 2007-2008," he said in an interview with NATO-TV.
"I think generally, it has borne fruit."
He said it has been a difficult journey, rife with setbacks, but coalition forces have halted the momentum of the Taliban in much of the country and reversed the insurgent hold in restive Helmand province.
Petraeus' experience in working with the CIA on counterinsurgency efforts in the field was cited as a reason for his nomination as the spy agency's director.
CNN's David Ariosto, Moni Basu and Samson Desta contributed to this report.