The Martian has a happy ending for protagonist Mark Watney, who, as a result of a series of unfortunate events, has been stranded alone on Mars for about a year and a half. After an intrepid journey from Acidalia Planitia to the site of the Ares IV Mars Ascent Vehicle in the Schiaparelli Crater, Mark manages to launch himself into orbit after modifying the MAV with the help of NASA to help it lose drastic amounts of weight.
In an action which would have been described as mutiny by NASA, the Ares III crew had changed Hermes' path to a trajectory which would enable them to do a "Mars fly-by" on SOL 549. They were able to intercept Watney, and with the help of his crewmate Beck, he made it back onto Hermes.
There is a stark difference between the ending of the book and of the movie: the book ends soon after Watney's successful return to Hermes, while we are not given information about Hermes's return to Earth. The movie depicts Mark Watney safely back on Earth. The book ends with Mark and the crew still 211 days from Earth.
The last passage of the book includes a reflection from Watney in which he considers the massive amount of time, effort, and money spent to rescue him. He considers that his crewmates sacrificed a year of their lives to come back for him and that monumental efforts were made by NASA and JPL to make saving his life possible.