Commander Mark Kelly, the dashing astronaut who piloted the final mission for space shuttle Endeavour and stood by the bedside of his recovering congresswoman wife Gabrielle Giffords, announced his retirement from the Navy and NASA over Facebook Tuesday morning.

"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 wrote on his official Facebook page.

Kelly's wife Giffords underwent surgery in May to repair her skull, following a shooting that almost killed her in January -- an incident that has clearly been weighing on the mind of the pilot and astronaut.

"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," Kelly wrote. "I love them all very much and there is no doubt that we will move forward together."

NASA chief Charles Bolden expressed his appreciation for Kelly, who he called "an extremely accomplished member of the astronaut corps."

"We deeply respect his achievements and his decision to focus on his family. We continue to send out our thoughts and prayers to Mark and his wife, Rep. Gabrielle Giffords, as she makes a remarkable recovery. He has helped us build a space program poised to take advantage of the many opportunities in our bright future."

Kelly and his wife announced Tuesday plans to work a book together chronicling everything from their careers and courtship to the Jan. 8 tragedy when a gunman shot Giffords during a political event in Tucson, Ariz. Scribner will publish the book at a date to be determined.

"Since Jan. 8, it's been really touching to us to see how much support there is for Gabby and her recovery, and how much interest there is in how she's doing and her story," Kelly, a Navy captain, told The Associated Press during a recent interview from Texas.

Kelly's retirement comes at a turning point for NASA's space mission, with the final flight of space shuttle Atlantis -- a resupply mission for the International Space Station -- set to blast off on July 8. Following that mission, NASA will exit the Earth-to-orbit business to focus on expeditions to asteroids and Mars.

The space agency hopes private companies such as SpaceX and Boeing will pick up the slack for hauling cargo and crew to the space station. Kelly was aware of the controversy surrounding the shuttle retirement, but wrote that he believed NASA would rise to the challenges before it.

"I know that as our space program evolves, there are those who will question NASA's future. I am not among them," wrote Kelly. "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."

Although he is stepping down for now, Kelly did not rule out an eventual return to service.

"After some time off, I will look at new opportunities and am hopeful that one day I will again serve our country," he wrote.

Comments posted on the decorated pilot and astronaut's Facebook page conveyed messages of goodwill.

"Thank you for proudly serving our country and NASA," wrote Facebook user Tiffany DiBenedetto. "You have made us proud. All the best to you and to Gabrielle."

"Congratulations and thank you, Captain Kelly," wrote Mike Salsgiver. "Your service through excellence, combined with your unbelievable love and commitment to your family, is a true inspiration to millions. May God bless you, your wife and family, and may He continue to bless the United States of America."