The novel is structured with flashbacks of the main protagonist, Ryland Grace, before the launch and the current events relating to the time on Hail Mary, intertwined. Ryland is a science teacher who suddenly gets recruited by the UN to help prevent the end of the world that could be caused by a certain solar event. The space exploration concludes that an alien organism is eating up the solar energy, which will eventually cause a new Ice Age on Earth.
Eva Stratt, a person in charge of the Hail Mary mission to save the Earth, recruits people who have a specific gene that will enable them to survive a four-year coma, until they reach the Tau Ceti star - a star that is immune to the Astrophage (the name of the solar-devouring alien force) to collect and send the information and material necessary to save the Earth. There is a catch to the Hail Mary mission. Namely, those who are sent won’t ever come back, which makes it a suicide mission.
One of the intended crewmates dies in a tragic accident, and Stratt tries to convince Grace to take part in the mission. He strongly refuses, but Eva Stratt forces him into the cabin with an amnesia-inducing programming on the computer so that he doesn’t cause trouble after he wakes up four years later.
Four years later, Grace wakes up on Hail Mary circling around Tau Ceti. He has no memory of who he is, and discovers the rest of the crew dead. He holds funerals for them. Some time passes, and the ship discovers another spaceship circling the star. The ship is of extraterrestrial origin, and Grace calls it Blip-A. He establishes communication with the ship and discovers that there is also only one crew member remaining there. They connect forces and Grace meets with the member, who comes from 40 Eridani solar system. He learns that the Eridian species is not as evolved as humans, and the member has an appearance of a large spider with no eyes.
The two work together to investigate and solve the problem of Astrophage and Rocky (the name Grace gave to the Eridian) promises to give Grace enough fuel to return to his planet. They discover that the solution is a substance Grace calls Taumoeba which devours Astrophage particles and prevents its damage. Rocky gives the fuel for Grace’s return home with the information about the Taumoeba.
On his way home, Grace discovers that Taumoeba is also able to cause damage to Blip-A, which will kill Rocky before he manages to rescue his home planet. He decides to send the material and information to the Earth and return to save Rocky and Eridians. He succeeds in his mission, but knows that it means his death because he can’t survive on the Eridian planet.
The novel skips ahead in time, and it is revealed that Grace is safely living on the Eridian planet in an artificially made area that resembles Earth. He has aged a lot and has the means to go back to the Earth, but he keeps leaving it for another day. The novel ends with Grace teaching young Eridians about science.