In this, the final episode of the trilogy that began with Star Trek: The Wrath of Khan
, the crew of the enterprise leaves Vulcan, having voted to return to Earth to face punishment for their actions in Star Trek III: The Search for Spock
. They depart for Earth in the Klingon scout-class warbird they captured from Commander Kruge at the Genesis planet, now re-christened by Dr. McCoy as the "H.M.S. Bounty".
Meanwhile, a strange probe is also on course for Earth. As it travels, it emits a strange signal that disables all of the technology that it encounters, leaving a trail of damaged starships and star bases in its wake. Upon its arrival at Earth, the planet itself is jeopardized as high technology fails, the oceans are evaporated, and the atmosphere is ionized. Clouds block out the sun, which Earth cannot survive without.
Arriving within our solar system, the crew of the Bounty analyzes the strange signals from the probe and realizes they are a representation of whale song, an apparent attempt to communicate with the long-extinct humpback whales that formerly lived in Earth's oceans. The crew decides that the only way to answer the probe's signals is to travel back in time and obtain humpback whales.
Using the slingshot-around-the-sun maneuver first developed in the TV series, they take the Bounty back to Twentieth Century Earth where two whales are detected in the vicinity of San Francisco. Cloaked, the Bounty lands in Golden Gate Park, but the strain of time travel was too much for the ship: its dilithium crystals have been damaged.
Once in the city, the crew splits to accomplish three different missions: Locate the whales, build a tank within the Bounty that can carry the whales, and locate a source of high-energy photons with which the crystals can be regenerated.
Kirk and Spock go in search of the whales, locating them at Sausalito's Cetacean Institute (a re-dress of the Monterey Bay Aquarium). There, they encounter Dr. Gillian Taylor, the assistant director of the Institute and keeper of the whales. Spock dives into the whale tank and mind-melds with one of the whales, but is caught in the act and Kirk and Spock are ejected from the Institute. Walking away, they are given a ride by Dr. Taylor. Kirk eventually confesses what they are up to, to Dr. Taylor's disbelief, but upon being dropped off at Golden Gate Park, she barely observes him transporting back into the Klingon warbird.
Meanwhile, McCoy and Scotty set off in search of a piece of plastic suitable for creating a transparent tank wall in the warbird. In Chinatown, they use the formula for transparent aluminum as a bribe to obtain the material they need. Sulu uses a stolen helicopter to transport it back to the Bounty.
Finally, Uhura and Chekov go to the Alameda Naval Station to obtain high-energy photons from the reactor of a nuclear "wessel" (which turns out to be the U.S.S. Enterprise). The photons are obtained and Uhuru is able to return to the Bounty, but Chekov is captured and interrogated by naval investigators. Attempting escape, he falls, is seriously injured, and is taken to hospital.
Overnight, at the Cetacean Institute, the whales have been released (owing to the advanced pregnancy of the female of the pair). Gillian rushes back to Golden Gate Park where she sees Sulu's helicopter lowering the plastic wall into the cloaked (and thus, invisible) Klingon warbird. Screaming for help, she is beamed aboard, confirming Kirk's story of the previous evening.
Together, she, Kirk, and McCoy rescue Chekov from the hospital, healing both Paval and, along the way, an old woman suffering from kidney failure. Racing back to the starship, they board and the warbird leaves to re-capture the whales from the open sea, rescuing them just as a whaling ship fires a torpedo.
Returning in time to the 23rd century, they crash-land in San Francisco Bay near the Golden Gate Bridge. Freed into the ocean, the whales respond to the probe and it is finally satisfied, halting the transmission of its dangerous signal and allowing the Earth to survive.
A brief trial is then held for the crew of the Bounty, but as a result of having saved the planet yet again, Starfleet and Federation officials are predisposed towards lenience. All charges arising from the action in ST-III are dropped except for the charge against Kirk of disobeying a direct order. This charge results in him being busted down in rank from Admiral to Captain and he is once again assigned the command of a starship: NCC-1701A, a duplicate of the earlier Enterprise.