Ryland Grace is a scientist on board an interstellar spacecraft called the "Hail Mary". He has lost parts of his memory due to him being placed in an induced hibernation as the spacecraft travels several light years, but eventually remembers that his mission is to travel to a distant star, Tau Ceti, to investigate how to save Earth from an organism called astrophage that is feeding on the Sun and causing global cooling. As he reaches Tau Ceti, he encounters an alien he names "Rocky", and together they discover a predator organism called Taumoeba that can control astrophage. As the mission progresses he regains his memory and remembers that he was put in the Hail Mary against his wishes, without enough fuel for a trip to return home but with enough to send the information back to earth to save the Sun from dying.
Upon the mission's end, Rocky is able to provide Grace with enough fuel for him to return home, and Grace and Rocky part ways. However, Grace turns his ship around to save Rocky upon discovering that the Taumoeba would likely damage Rocky's ship, leaving Rocky stranded in deep space. Grace eventually saves Rocky, returning the favor of Rocky previously saving Grace's life, but does not have enough fuel to go back to Earth, instead staying at Rocky's home planet of Erid until his ship is repaired and refueled again for Grace to go home. Whilst his ship is being repaired, Grace finds solace in planet Erid, being able to become a schoolteacher and otherwise having a comfortable life provided by the Eridians.
Grace's ship is then repaired, facing him with two options:
A. Stay on planet Erid with his newfound best friend Rocky; or
B. Return home to Earth as the hero who saved the Sun from dying.