NASA astronaut Mark Watney, a botanist and mechanical engineer, has been left stranded on Mars after the crew of the Ares 3 mission were forced to evacuate their landing site in Acidalia Planitia due to an intense dust storm with high winds. Watney was impaled by an antenna during the evacuation and believed dead. His injury proves relatively minor, but with no way to contact Earth, Watney must rely on his own resourcefulness to survive. He begins a log of his experiences for those who might discover it long after his death. Watney begins growing potatoes in the crew's Martian habitat (or Hab) and burns hydrazine to make water. NASA discovers that he is alive when satellite images of the landing site show evidence of his activities; they begin working on ways to rescue him, but withhold the news of his survival from the rest of the Ares 3 crew, on their way back to Earth aboard the Hermes spacecraft, so as not to distract them.
Seeing it as his only chance at rescue, Watney plans to drive 3,200 kilometres (2,000 mi) to Schiaparelli craterwhere a subsequent mission, Ares 4, will land in four years. He begins modifying one of Ares 3's rovers for the journey, adding solar cells and an additional battery. He makes a three-week test drive to recover the unmanned Pathfinder lander and Sojourner rover and brings them back with him to the Hab, allowing him to contact Earth. Mitch Henderson, the Ares 3 flight director, convinces NASA Administrator Teddy Sanders to allow him to inform the Ares 3 crew of Watney's survival; his crewmates are thrilled, except for Melissa Lewis, the commander, who is guilt-stricken at leaving him behind.
The canvas at one of the Hab airlocks tears due to Watney's ongoing use of it, collapsing the Hab and nearly killing Watney. He repairs the Hab, but his plants are dead, threatening him again with starvation. Setting aside safety protocols, NASA hastily prepares an unmanned probe to send Watney supplies, but the probe's rocket disintegrates on liftoff. A deal with the China National Space Administration provides a ready booster to try again, but with no time to build a probe with a soft-landing system, NASA is faced with the unlikely prospect of building one whose cargo will survive crashing into the Martian surface at 300 meters per second (671 MPH). Meanwhile, astrodynamicist Rich Purnell has devised a "slingshot" trajectory that could get Hermes and the Ares 3 crew back to Mars on a much-extended mission to save Watney, using the Chinese rocket to send a simpler resupply probe to Hermes as it passes Earth. Sanders vetoes the "Rich Purnell Maneuver" as involving too much risk for the other crewmembers, but Henderson secretly emails the maneuver to Hermes. All five of Watney's crewmates agree to the plan, and once they begin the maneuver, NASA is compelled to send them the supply ship to prevent their starvation.
Watney resumes modifying the rover, since the new rescue plan requires him to lift off from Mars in the Ares 4 mission's Mars Ascent Vehicle (MAV), which is already at Schiaparelli Crater as part of the long preparations for that visit. While working on the rover, Watney accidentally shorts out the electronics of Pathfinder, again losing the ability to communicate with Earth (except for spelling out Morse code with rocks). The resupply probe launches and docks with Hermes successfully. As Watney prepares to leave for Schiaparelli, NASA discovers that a dust storm is approaching Watney's course, potentially stranding him on the journey if the rover's solar cells cannot recharge, but has no way to warn him. While crossing Arabia Terra, Watney becomes aware of the encroaching dust storm and improvises a rough measurement of the direction of its movement, allowing him to go around it.
Surviving a rover rollover on his descent into Schiaparelli, Watney reaches the MAV and reestablishes contact with NASA. He receives instructions on the radical modifications to the MAV that are necessary to reduce its weight and allow it to intercept Hermes during its flyby. The modifications leave a large hole in the front of the MAV, which Watney is directed to cover with Hab canvas. During launch, the canvas patch tears, slowing the liftoff and leaving the MAV on a course too far from the Hermes for Watney to be rescued. Lewis develops a plan to intercept the MAV by firing Hermes' attitude thrusters, then slowing down to match the MAV's velocity by blowing a hole in the Hermes front airlock with an improvised sugar-and-liquid-oxygen bomb. A crewman on a tether uses a Manned Maneuvering Unit to reach Watney aboard the MAV and carry him back to Hermes. In a final log entry, Watney expresses his joy at being rescued, reflecting on the human instinct to help those in need.