The story takes place eight years after the events of «Prelude to Foundation», in the year 12,028 of the Galactic Era (G.E.). Gary Seldon continues work on the concept of psychohistory with the secret support of Prime Minister Edо Demerzel (who is, in fact, a robot, R. Daniel Olivo), striving to turn this hypothetical theory into a practical tool for influencing events on the scale of the entire Galaxy.
On Trantor, the capital of the Galactic Empire, a movement gains strength under the leadership of Laskin Joranum. Using demagogic calls for social justice, he aims to remove Demerzel and become prime minister—and then king. This threatens the Empire with civil war and unrest that would destroy the state and prevent the development of psychohistory from being completed. At the same time, on his post, Olivo finds it increasingly difficult to reconcile decision-making that affects the life of the Empire with the zero law of robotics (a robot cannot harm all of humanity). Gary Seldon finds a way to deal with the threat from Joranum, who is ultimately sent into exile to an isolated planet, where he later dies. After the crisis is resolved, Cleon I appoints Seldon as the new prime minister, with Demerzel also helping.
Year 12,038 of G.E. With the aim of overthrowing Seldon’s government, the remnants of Joranumites engage in sabotage of the planet’s infrastructure. In response, the prime minister sends his adopted son Reicus Seldon as a spy into the movement, but he is exposed. Using a strong drug, Reich is made an accomplice to an attempt on his adopted father, but the murder is prevented with the help of an officer of Manella Dubankow’s security service. Nevertheless, Emperor Cleon I becomes the victim of a subsequent assassination attempt by the gardener.
Year 12,048 of G.E. After the death of Cleon I, the two-hundred-year dynasty of the Entunes that had ruled the Empire is removed from power by a military junta. The psychohistorical project makes significant progress, largely thanks to the mathematical calculations of Tamvilel Elar. Seldon resigns, returning to the university to continue working on psychohistory, interest in which began during Cleon I’s time. The project’s participants manage to make some predictions about the near future of the Empire. To better control psychohistory, the junta plans to get rid of Seldon, and for this purpose its agent—turns out to be Elar—kills Seldon’s wife and defender Dors Venabili (who is also a robot). But with his advice, the new power’s political collapse accelerates, allowing Gary to keep working on psychohistory.
Year 12,058 of G.E. After the junta is overthrown, a far relative of Cleon I—Agis XIV—ascends to the throne, whose power is seriously limited by parliament. The decline becomes increasingly evident in many spheres both on Trantor itself and throughout the Galaxy. For Gary Seldon to continue his work, his psychohistory colleagues need open access to the Galactic Library, but society’s negative attitude toward him as a “predictor of trouble” and the worsening finances of the Empire stand in his way. Reich with his family goes to the planet Santanni, while only his daughter Wanda stays with Gary. Soon, he discovers that she has the ability to influence the human mind. Using her talent to solve the problem with the Galactic Library, Gary decides to create two Academies that will ensure the formation of the Second Empire. The first will focus on physical sciences in order to become the dominant force in the Galaxy, and the second—secretly from the people—will study mentalism and psychohistory, overseeing the first.
Year 12,069 of G.E. Gary Seldon dies on Trantor. At his funeral ceremony is also the former prime minister, Edo Demerzel.