Ken Mattingly, who orbited the moon and commanded a pair of NASA shuttle missions, but who was remembered as well for the flight he didn’t make — the near-disastrous mission of Apollo 13 — died on Tuesday in Arlington, Va. He was 87.
His death was confirmed by Cheryl Warner, a NASA spokeswoman. She did not specify the cause or say whether he died at home in Arlington or in a hospital there.
Mr. Mattingly, a former Navy jet pilot with a degree in aeronautical engineering, joined NASA in 1966. But his first spaceflight didn’t come until April 1972, when the space agency launched Apollo 16, the next-to-last manned mission to the moon.
Piloting the spacecraft’s command module in orbit while holding the rank of lieutenant commander, he took extensive photos of the moon’s terrain and conducted experiments while Cmdr. John W. Young of the Navy and Lt. Col. Charles M. Duke Jr. of the Air Force, having descended in the lunar lander, collected rock and soil samples from highlands near the crater known as Descartes.
While the three astronauts were en route back to Earth, Commander Mattingly stepped outside the spacecraft — which he had named Casper for the resemblance, as least in a child’s eye, between an astronaut in a bulky spacesuit and the cartoon character Casper the Friendly Ghost.
Maneuvering along handrails while connected to the spacecraft by a tether, he retrieved two attached canisters of film with photos of the moon that he had taken from inside the capsule for analysis back on Earth.
When the Apollo program ended, Commander Mattingly headed the astronaut support office for the shuttle program, designed to ferry astronauts to and from an eventual Earth-orbiting International Space Station.
In the summer of 1982, he commanded the fourth and final Earth-orbiting test flight of the shuttle Columbia, which completed 112 orbits. He was also the commander of the first space shuttle flight conducted for the Department of Defense, a classified January 1985 mission aboard Discovery.
All those achievements came after he had been scrubbed at virtually the last moment from the flight of Apollo 13 in April 1970.
He was to have orbited the moon in the command module while Cmdr. James A. Lovell Jr. of the Navy and Fred W. Haise Jr. explored the lunar surface.
But NASA removed Commander Mattingly from the crew in the final days before launching, when blood tests determined that he had recently been exposed to German measles from training with Colonel Duke, the backup lunar module pilot, who in turn had contracted it from his proximity to an infected child at a neighborhood party. Commander Mattingly was the only one of the Apollo 13 crewmen who were found to lack antibodies against the illness.
His backup, John L. Swigert Jr., became the command module pilot, leaving Commander Mattingly to watch the progress of the flight from mission control.
“Tall and thin, his brown crew-cut hair almost gone, Mattingly was perhaps the most private man in the Astronaut Office,” Andrew Chaikin wrote in “A Man on the Moon: The Voyages of the Apollo Astronauts” (1994).
He was also, Mr. Chaikin added, “in the depths of the worst depression of his life” after he was taken off Apollo 13.
But he would not be idle.
On the flight’s third day, an oxygen tank explosion in the spacecraft’s service module when it was some 200,000 miles from Earth knocked out power and oxygen in the command module housing the three astronauts, raising fears that they would be stranded in space.
Commander Mattingly did not, in fact, develop German measles, and he played a significant part in the plan developed by the astronauts and mission control in Houston to get them home safely.
The three astronauts crowded into the undamaged lunar module, although it had been built to hold only two astronauts and was designed solely for landing on the moon and then returning to the orbiting mother ship.
Commander Mattingly read off a long and detailed list of instructions for the astronauts to follow as they used the lunar lander as a “lifeboat” to get them back toward Earth while short on power.
When the spacecraft and the attached lunar lander approached Earth, the astronauts transferred back into the command module, which still had some battery power and oxygen and bore the heat shield needed for the descent through the atmosphere. The lunar module and the heavily damaged service module were jettisoned, and the astronauts touched down in the Pacific. They were flown aboard a helicopter to the recovery ship, the aircraft carrier Iwo Jima.
The harrowing episode was recounted in the 1995 Hollywood film “Apollo 13,” in which Commander Mattingly was played by Gary Sinise.
Thomas Kenneth Mattingly II, known to his colleagues as Ken, was born in Chicago on March 17, 1936, and grew up in the Miami area, where his father worked for Eastern Airlines.
“I built every model airplane that I could find, ate every box of cereal that had a cutout paper airplane on the back,” he told NASA in a 2001 oral history interview.
His father secured passes for him to fly on Eastern between Miami and New York. As Mr. Mattingly recalled, “If you went up the East Coast from Miami, up north and back, that was a long day.”
He received a bachelor’s degree from Auburn University in 1958, entered the Navy as an ensign and, after receiving his wings in 1960, flew off aircraft carriers. He joined the astronaut corps after attending test-pilot school at Edwards Air Force Base in California.
After his Apollo and space shuttle flights, Mr. Mattingly continued to work for NASA in the 1980s. He retired from the space agency and the Navy as a rear admiral and went on to work for aerospace companies.
His survivors include his wife, Kathleen (Ruemmele) Mattingly, and a son, Thomas III.
When “Apollo 13” was released, Mr. Mattingly fielded questions anew about missing out on the flight.
“It was very painful to be told a couple of days before launch that you are not going to go, but there was so much invested in this mission that it really was the only choice,” he said in an interview with Auburn University.
He added that over the years he wondered what would have happened if he had been on the flight. “But I can guarantee you from a feelings point of view,” he said, “I would have rather been there, no matter what happened.”
Alex Traub contributed reporting.