ARLINGTON, Va. — Calling it "the honor of my life," Defense Secretary Leon Panetta said farewell to the U.S. military Friday, capping a venerated public service career that spanned four decades and included stints as a lawmaker, a top White House official and the spy chief who oversaw the killing of Osama bin Laden.

President Barack Obama, honoring his first-term Pentagon chief at a ceremony at a military base outside Washington, said Panetta would be remembered for welcoming more Americans into the military by opening combat roles to women and overseeing the repeal of a ban on gays serving openly — "In short, for making our military and our nation that much stronger."

"Every decision he has made has been with one goal in mind: taking care of our sons and our daughters in uniform and keeping America safe," Obama said.

Panetta, the son of immigrants and self-described son of Italy, said he hoped in some small way to have helped to fulfill the dreams of his parents. As he spoke, row upon row of U.S. troops stood behind him, rifles and bayonets at their sides.

"It's been, for me, a hell of a ride," said Panetta, who served in Congress and in the Clinton administration before becoming Obama's CIA director and ultimately serving a brief but pivotal term as defense secretary.

"I will never forget the pride and exhilaration when I walked out of the White House after the president announced the success of the bin Laden operation," he recalled. "I could hear the chants of those people who were gathered around the White House and in Lafayette Park yelling, 'U.S.A. U.S.A.'"

Looming awkwardly over the formal farewell ceremony was the ongoing uncertainty about Panetta's replacement.

Obama has nominated former Nebraska Sen. Chuck Hagel, a Republican, to take over for Panetta, but Republicans have expressed deep misgivings about his previous statements about Iran, Israel and other issues. Days after postponing a vote on Panetta's confirmation amid GOP demands for more information, the Democratic chairman of the Senate's military panel said Friday he will press ahead with a vote.

Panetta has said he will remain on the job until the Senate confirms a successor. Then he will finally leave the Pentagon, returning home to his walnut farm in Carmel, Calif., after more than 40 years in Washington.