Veteran astronaut Mark Kelly, the husband of Rep. Gabrielle Giffords (D-Ariz.), announced his retirement from NASA and the U.S. Navy June 21 after more than two decades of service.

“Today, I am humbled to announce that after 25 years of service to our country, I am retiring from the United States Navy and leaving NASA, effective Oct. 1,” Kelly, 47, said in a statement he posted on Facebook.

Kelly’s career at NASA began in 1996, and has included four space shuttle flights, two each on the shuttles Endeavour and Discovery. He joined the Navy as an aviator in 1987 and holds the rank of captain.

On May 16, Kelly commanded Endeavour on its STS-134 flight, the second-to-last mission of NASA’s 30-year space shuttle program. Kelly landed Endeavour for the last time June 1 at Kennedy Space Center in Florida.

In early January, Giffords suffered a gunshot wound to the head at a constituent meeting in Tucson. After critical surgeries and intense rehabilitation, Giffords was able to travel to Florida in April and May to watch her husband’s launch into space.

During Giffords’ recovery, Kelly stayed by her side and eventually she was moved to a Houston-area hospital to allow Kelly to resume training for Endeavour’s final mission. NASA had tentatively named a backup commander for the flight, but Kelly later resumed training as Giffords’ condition improved.

“I will be forever grateful to the NASA managers who trusted me with this enormous responsibility during such a difficult period in my personal life and to those leaders in the United States Navy who prepared me to handle these challenging times,” Kelly said.

Kelly stated that despite his departure from NASA, he remains confident in the future of the nation’s space program.

“I know that as our space program evolves, there are those who will question NASA’s future,” Kelly said. “I am not among them. There isn’t a group more dedicated to its mission or more capable than the outstanding men and women of NASA. Exploration is a critical component of what makes our country great. We will continue to explore and NASA will continue to lead that effort.”

The decision to retire will allow Kelly to spend more time with his family, and to continue to focus on his wife’s recovery, he said.

“As life takes unexpected turns we frequently come to a crossroads,” Kelly said. “I am at this point today. Gabrielle is working hard every day on her mission of recovery. I want to be by her side. Stepping aside from my work in the Navy and at NASA will allow me to be with her and with my two daughters. I love them all very much and there is no doubt that we will move forward together. After some time off, I will look at new opportunities and am hopeful that one day I will again serve our country.”