WASHINGTON—Gen. Stanley McChrystal ended his 34-year career as an Army officer Friday in an emotional retirement ceremony at his military headquarters here, marking the last chapter of his swift and stunning fall from grace.

Before a crowd of a few hundred friends, family and colleagues on the Fort McNair parade grounds under an oppressively hot July sun, McChrystal said his service didn’t end as he hoped. But he regretted few decisions he had made on the battlefield, cherished his life as a soldier and was optimistic about his future, he said.

“I trusted and I still trust,” McChrystal said. “I cared and I still care. I wouldn’t have it any other way.”

The former commander of U.S. forces in Afghanistan was fired last month after Rolling Stone magazine published an article titled “The Runaway General” that quoted scathing remarks he and his aides made about their civilian bosses.

McChrystal complained President Barack Obama had handed him “an unsellable position” on the war. The general’s closest advisers mocked other government officials, including Vice President Joseph Biden, as fools who were ignorant of the complexities of war.

“Biden? Did you say, ‘Bite me?'” one aide is quoted saying.

Shortly after the article was published, McChrystal was sent packing.

In his 18-minute farewell tribute before the VIP-studded crowd, McChrystal made light of the episode. He warned his comrades in arms: “I have stories on all of you, photos of many, and I know a Rolling Stone reporter.”

But McChrystal also sounded a more serious note, when he talked about the pain of leaving behind unfulfilled commitments in Afghanistan and watching colleagues ensnared in the scandal.

“There are misconceptions about the loyalty and service of some dedicated professionals that will likely take some time, but I believe will be corrected,” he said.

Still, he said he was approaching the future with optimism.

“I need to celebrate,” said McChrystal, who inspired intense loyalty among many of those who served under him.

McChrystal spent much of his speech paying tribute to his wife of 33 years, Annie, who watched tearfully from the front row. He described her endless support, as he repeatedly headed off to war, and as inspiring him during dark times following the 2001 terrorist attacks.

“She’s here, like she’s always been there when it matters, always gorgeous,” he said.

Soldiers attending the ceremony were allowed to forgo their formal dress uniforms in lieu of combat fatigues — an apparent tribute to a war commander fresh from battle and whose career was marked by more secret operations to snatch terror suspects than by pomp and circumstance.

Wearing his own Army combat uniform for the last time, the four-star general received full military honors, including a 17-gun salute and flag formations by the Army’s Old Guard.

U.S. Defense Secretary Robert Gates, who appeared to fight back tears as he gave McChrystal a hero’s tribute, “Over the past decade, arguably no single American has inflicted more fear, more loss of freedom and more loss of life on our country’s most vicious and violent enemies than Stan McChrystal,” Gates said.

Afghanistan’s top representative to the United States said his country would remember McChrystal for generations to come.

“We will never forget the sacrifices that you and those under your command have made to make Afghanistan safer for our children,” Ambassador Said Tayeb Jawad said.

A close aide to the general, Col. Charles Flynn, says McChrystal plans to live in the northern Virginia area after moving out of his home in Washington’s Fort McNair.