David Petraeus, the general widely credited with rescuing a failing U.S. war in Iraq, retired from the Army on Wednesday with a word of warning: Coming budget cuts must not impair the U.S. military's ability to fight a full range of conflicts, from major land wars to Iraq-like insurgencies.

Petraeus, 58, used his farewell speech to thank those who have mentored and supported him in 37 years of service. But he also made clear his concern that political pressures to lighten the nation's debt burden could force the military to retrench in ways that hurt U.S. security and U.S. troops.

"As our nation contemplates difficult budget decisions, I know that our leaders will remember that our people, our men and women in uniform, are our military," he told an audience sprinkled with figures from his past, including former West Point classmates. "And that taking care of them and their families must be our paramount objective. Beyond that it will be imperative to maintain a force that not only capitalizes on the extraordinary experience and expertise in our ranks today but also maintains the versatility and flexibility that have been developed over the past decade."

The Pentagon already is preparing to reduce defense spending by upward of $400 billion over the next 10 years, and Congress may demand even bigger cuts.

Petraeus looked back over his celebrated career, which began when he was commissioned a second lieutenant after graduating from West Point in June 1974. He recalled the unease he felt on his first day at the military academy and the pride that came from soldiering for nearly four decades.

He will begin a new chapter next week when he takes over as director of the Central Intelligence Agency, succeeding Leon Panetta, who gave up the spy chief job to become defense secretary last month. Panetta, who is on vacation in California, did not attend the Petraeus ceremony.

Petraeus quoted President Theodore Roosevelt's famous remark about men who dare to do great things, "so that his place shall never be with those cold and timid souls who knew neither victory nor defeat."

Petraeus thanked those he has served with and said he leaves with confidence that the nation will avoid unwise decisions on defense spending cuts. He alluded to the difficulties the military faced at the outset of the Iraq and Afghan conflicts in adjusting to counterinsurgency warfare.

"We have relearned since 9/11 the timeless lesson that we don't always get to fight the wars for which we are most prepared or most inclined," he said. "Given that reality, we will need to maintain the full-spectrum capability that we have developed over this last decade of conflict."

The Petraeus ceremony was hosted by Deputy Defense Secretary William Lynn, who presented the general with a Distinguished Service Medal, and Navy Adm. Mike Mullen, who heaped praise on the man who many had expected to succeed Mullen as chairman of the Joint Chiefs of Staff. President Barack Obama instead chose to make Petraeus his next CIA chief.

Mullen, who is due to retire Oct. 1, called Petraeus a visionary and said the general and his wife, Holly, are "national treasures."

"Dave has, over the last decade, advised two presidents, changed the course of two wars, transformed our military and, perhaps most important of all, reminded Americans once again that with the right ideas and the right leadership, almost anything is possible," Mullen said.

Petraeus soared to public acclaim in 2007-08 with his surprising success in reversing an escalation of insurgent violence in Iraq.

At a September 2008 ceremony in Baghdad marking the end of Petraeus' 19 months in command, then-Defense Secretary Robert Gates credited him with dealing a "tremendous, if not mortal, blow" to an insurgency that two years earlier seemed beyond U.S. or Iraqi government control.

"I believe history will regard you as one of our nation's great battle captains," Gates told Petraeus.

Petraeus is credited with similarly solidifying gains against the Taliban in Afghanistan, though he himself says progress is "fragile and reversible."

Petraeus also is seen as one of the Army's most accomplished accumulators of personal publicity. The Iraq war made him a household name. A July 2004 Newsweek magazine cover featuring Petraeus posing in front of a Black Hawk helicopter asked, "Can this man save Iraq?"

Petraeus is sometimes mentioned as a potential Republican presidential candidate, although he has said repeatedly he has no interest in politics.

His high public profile, following what most regarded as a successful first tour in Iraq in 2003, triggered some resentment in the Pentagon during Donald H. Rumsfeld's tenure as defense secretary. For that reason some saw his next assignment, to the Combined Arms Center at Fort Leavenworth, Kan., as a put-down.

"Various folks had said I've been sent to exile at Leavenworth," a bemused Petraeus told the Pentagon Channel.

But it was during that assignment in 2005-06 that Petraeus co-authored with Marine Gen. James Mattis an updated manual on how to fight a counterinsurgency campaign. It was a major success, and not just inside the military. Within a week of publication, the manual was downloaded 1.5 million times.

Petraeus put those ideas into practice when he was sent back to Baghdad as the top U.S. commander, arriving in February 2007 at a peak of sectarian violence and a low point of U.S. public confidence in the war.

In the fall of 2008, President George W. Bush made Petraeus commander of U.S. Central Command, overseeing all U.S. military operations in the greater Middle East, including Afghanistan and Pakistan. And when the top U.S. commander in Afghanistan, Gen. Stanley McChrystal, was abruptly relieved of duty in June 2010 for comments in a magazine story, Obama asked Petraeus to take over in Kabul and the general quickly agreed.


AP National Security Writer Robert Burns can be reached on Twitter (at)robertburnsAP.

AP Intelligence Writer Kimberly Dozier can be reached on Twitter (at)kimberlydozier.