Mark Kelly, the US astronaut who commanded the final flight by the shuttle Endeavour, announced Tuesday he is retiring to spend more time with his lawmaker wife as she recovers from a gunshot wound to the head.

The pair will work together on a memoir to be published by a division of Simon and Schuster, Scribner, a company spokesman said.

"As life takes unexpected turns we frequently come to a crossroads. I am at this point today. Gabrielle is working hard every day on her mission of recovery. I want to be by her side," Kelly said on his Facebook page.

Kelly, 47, took on a high-profile role in the US space agency in the aftermath of the January shooting, which gravely wounded his wife Gabrielle Giffords at a political meeting in Arizona.

His painstaking decision to command Endeavour's final flight -- the second to last mission by a US space shuttle before the program ends later this year -- came as Giffords was busy with a grueling rehabilitation program, and was supported by his family and many in the American public.

"Gabby and I are forever grateful for the heartfelt support we've received over these many months. We are looking forward to sharing our story," Kelly said in a statement issued by Scribner.

Last week Giffords was discharged from the hospital, five months after she was shot in the head at point-blank range in an attack that shocked the nation.

She has moved into her husband's home in League City, Texas and will continue outpatient therapy, her office said.

Six people, including a federal judge and a nine-year-old girl, were killed and 12 others wounded in the January 8 shooting spree.

In March, the alleged shooter, Jared Loughner, was declared mentally unfit to stand trial. Experts found the 22-year-old to be schizophrenic and unable to help in his own defense or understand court proceedings.

Photos of a smiling Giffords -- who is battling to regain movement on the right side of her body after a bullet tore through the left side of her brain -- were posted on her Facebook page earlier this month.

Her aides have praised her determination but acknowledged she faces a long process of rehabilitation and has difficulty expressing complex thoughts. It remains unknown if she will return to her job as a member of the US Congress.

Scribner said the memoir "will recount their courtship, Ms. Giffords' rise in US politics, and the tragic January 8th shooting in Arizona."

"The book will also tell the story of her recovery process and will trace Mark Kelly's career from decorated Desert Storm combat pilot to his recent mission as the commander of space shuttle Endeavour's final flight."

The 30-year US space shuttle program is set to end later this year following the final flight by Atlantis, scheduled to launch July 8.

The closure of the shuttle program will leave the world's astronauts to rely on Russia's space capsules for transit to the International Space Station until a next-generation US space capsule can be built by private enterprise, which expert say could be 2015 at the earliest.

Kelly, who while in space last month expressed concern about a "memory gap" that could afflict the US space program in the interim between the shuttle and the next US spaceflight program, said in his announcement Tuesday that he continues to have faith in NASA.

"I know that as our space program evolves, there are those who will question NASA's future. I am not among them," said Kelly, whose twin brother Scott is an active astronaut with 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."

Kelly was a combat pilot during the first Gulf War and became an astronaut in 1996. He has flown four times to the International Space Station aboard the shuttles Discovery and Endeavour.

A portion of the authors' net proceeds would be donated to charity, Scribner said. A publication date has not yet been set.