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 but were hunted to extinction in the 21st Century. 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 20th 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 has depleted it's energy source of dilithium crystals.
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 giant beasts, and locate a source of high-energy photons with which the crystals can be regenerated. Kirk and Spock will locate the whales, Sulu, Scotty and Dr McCoy will find materials to build the tank and Chekov and Uhura will find an energy source to repair the dilithium core. The team finds their way into downtown San Francisco and discover that society of the 20th Century is still using money. Kirk sells the antique glasses give to him by McCoy to an antique dealer for $100 and splits the money between himself and the other teams.
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. During a regular tour, 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 along Marine Drive in San Francisco, they are found by Dr. Taylor and given a ride to Golden Gate Park to drop off Spock. While she drives them there, she asks them questions about their interest in the whales. Spock reveals that Gracie is pregnant and she stops the car suddenly, somewhat upset and astonished that Spock would know such a fact.
Kirk goes to dinner with Gillian and eventually tells her part of his plan -- he doesn't divulge that the whales are needed to save Earth in the future; he tells her he's attempting to repopulate the species. Gillian is incredulous but skeptical. Kirk asks her for the radio frequency of the tracker the whales will be tagged with and she avoids the question. However, she does reveal that the whales are to be released into the ocean at noon the next day. Kirk suddenly realizes he's on a much tighter timeline than he believed. When Gillian drops Kirk off at Golden Gate Park and he asks her for the frequency, she still refuses to turn it over. As she drives away she just misses 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. At a large plastics company called Plexcorp, they use the formula for transparent aluminum as a bribe to obtain the material they need from the plant's chief researcher, Dr Nichols. 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 aircraft carrier). 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 Mercy 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 Klingon warbird. Yelling for help, she is beamed aboard, confirming Kirk's story of the previous evening. She is a bit overwhelmed but tells Kirk about the whales being let loose during the night. Uhura is able to locate Chekov; McCoy gravely tells Kirk that they can't leave Chekov behind and at the mercy of 20th Century medicine. Spock concurs, saying that rescuing Chekov, while a potential impediment to their mission, is the "human thing to do."
Together, she, Kirk, and McCoy rescue Chekov from the hospital, healing both Paval and, along the way, an old woman suffering from kidney failure. They are chased by the police guarding Chekov and beam out of the hospital to Golden Gate Park from inside an elevator. They board and the warbird leaves immediately to re-capture the whales from the open sea. The whales are in the Gulf of Alaska and about to be harpooned by a whaling vessel when the warbird decloaks, scaring the hunters off. The extra weight of both the whales and the water that were beamed aboard the Bounty create a new problem: the added mass will make their time travel more difficult. Spock is able to alter their trajectory around the sun and they time warp back to the 23rd Century.
The ship crash-lands 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. The probe leaves Earth.
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.