The crew of the newly commissioned USS Enterprise (NCC-1701-A) are enjoying shore leave after the starship's shakedown cruise goes poorly. At Yosemite National Park, Captain James T. Kirk is camping with Spock and Dr. Leonard McCoy. Their leave is interrupted when the Enterprise is ordered by Starfleet Command to rescue human, Klingon and Romulan hostages on the planet Nimbus III. Learning of the Enterprise's mission, the Klingon Captain Klaa decides to pursue Kirk for personal glory.
On Nimbus III, the Enterprise crew discovers that renegade Vulcan Sybok, Spock's half-brother, is behind the hostage crisis. Sybok reveals the hostage situation was a ruse to lure a starship to Nimbus III. Sybok wants to use a ship to reach the mythical planet Sha Ka Ree, the place where creation began; the planet lies behind a seemingly impenetrable barrier near the center of the galaxy. Sybok uses his unique ability to reveal and heal the innermost pain of a person through the mind meld to subvert the wills of the hostages and crew members. Only Spock and Kirk prove resistant to Sybok; Spock is unmoved by the experience and Kirk refuses the Vulcan's offer, telling him that his pain is what makes him human. Sybok reluctantly declares a truce with Kirk, realizing he needs his leadership experience to navigate the Enterprise to Sha Ka Ree.
The Enterprise successfully breaches the barrier, pursued by Klaa's vessel, and discovers a lone blue planet. Sybok, Kirk, Spock, and McCoy journey to the surface, where Sybok calls out to his perceived vision of God. An entity appears, and when told of how Sybok breached the barrier, demands that the starship be brought closer to the planet. When a skeptical Kirk inquires, "What does God need with a starship?", the entity attacks him in retribution. The others doubt a god who would inflict harm on people for pleasure.
Sybok sacrifices himself and uses his telepathic powers in an effort to combat the creature. Intent on stopping the being, Kirk orders the Enterprise to fire a photon torpedo at their location, to little effect. Spock and McCoy are beamed back to the ship, but Klaa's vessel attacks the Enterprise before Kirk can be transported aboard. The vengeful entity reappears and tries to kill Kirk when Klaa's vessel destroys it in a hail of fire. Kirk is beamed aboard the ship, where Spock and the Klingon General Korrd force Klaa to stand down. The Enterprise and Klingon crews celebrate a new détente, and Kirk, Spock and McCoy resume their vacation at Yosemite.