Capt. Mark Kelly announced his retirement from the United States Navy and NASA on his Facebook page Tuesday.
"Words cannot convey my deep gratitude for the opportunities I have been given to serve our great nation," he said in the post. "From the day I entered the United States Merchant Marine Academy in the summer of 1982 to the moment I landed the Space Shuttle Endeavour three weeks ago, it has been my privilege to advance the ideals that define the United States of America."
His retirement will take effect on October 1, the post said.
Kelly said that he wants to be with his wife Rep. Gabrielle Giffords on her "mission of recovery."
Giffords was shot in the head January 8 in a mass shooting in Tucson that left six people dead. She was sent to the Houston facility January 21 to undergo intense rehabilitation. She was released last week to go through outpatient therapy.
Kelly, who has been with NASA for 15 years, completed his fourth and final shuttle mission on June 1. The space agency's 31-year shuttle program is coming to a close with the final mission, a flight of the shuttle Atlantis, in July.
In his Facebook posting, Kelly said he "will be forever grateful to the NASA managers who trusted me with this enormous responsibility during such a difficult period in my personal life."
Before joining the space program, Kelly served as a Navy pilot and flew combat missions in Operation Desert Storm from the aircraft carrier USS Midway.
"There is no higher calling" than military service, he said. "These are the people who inspire me with their sacrifice and timeless sense of duty."
Despite the end of the shuttle program, Kelly said he is optimistic about NASA's future: "Exploration is a critical component of what makes our country great. We will continue to explore and NASA will continue to lead that effort."