In the ending of “Transformers: The Last Knight,” Optimus Prime (voiced by Peter Cullen) plays a crucial role in saving Earth. Quintessa, the self-proclaimed creator of the Transformers, reveals her plan to drain Earth’s energy to restore Cybertron. Optimus is brainwashed and turned against humanity, serving Quintessa’s interests.
Cade Yeager (Mark Wahlberg) and his allies, including Bumblebee, team up with the Autobots to stop Quintessa’s plan. They embark on a mission to Cybertron to prevent the impending destruction. During a climactic battle, Optimus is freed from Quintessa’s control, and together with the Autobots, they save Earth.
The movie also introduces the idea of Unicron, a colossal Transformer that disguises itself as Earth. This revelation hints at potential future conflicts in the Transformers universe. The film concludes with Optimus Prime and the Autobots remaining on Earth to ensure its safety, setting the stage for future developments in the franchise.