In the previous film, The Search for Spock, the crew of Enterprise broke every law in the Starfleet handbook to bring their buddy Spock back to life. They even sacrificed Enterprise herself. Now stranded on the planet Vulcan in a Klingon spacecraft, the crew decides to return to Earth and accept punishment for their actions.
Meanwhile, a gigantic probe has appeared in Federation space. It's headed directly toward Earth, disabling the electronics of any ship that gets in its way. It's also releasing a bizarre audio signal that sounds strangely familiar to our ears.
The probe wreaks havoc when it reaches Earth, causing widespread power outages and kicking up extreme weather events. Starfleet determines that the audio signal is an attempt at communication, but lacking the ability to understand the message, they worry that the end is near.
As they fly back to Earth, the Enterprise crew learns about this sticky situation. Spock, in a stroke of genius, realizes that the audio signal is a modulated version of the song of the humpback whale—a species that has been extinct for hundreds of years.
The crew decides to time travel back to the 20th century and snag some humpbacks because that's apparently an easy thing to do. Once they make their quantum leap, they discover humpbacks in San Francisco and set their cloaked ship down in Golden Gate Park.
Kirk separates the crew into teams. Uhura and Chekov will search for a nuclear reactor they can use to recharge the ship; Sulu, McCoy, and Scotty will work on constructing a whale tank; and Kirk and Spock will be in charge of finding some humpbacks.
After discovering a local whale institute, Kirk and Spock meet Gillian Taylor, an expert in the field. She has two humpbacks in her care—Gracie and George—but they're going to be released into the wild in a few days, throwing a wrench into Kirk's plans. Kirk tries to convince Gillian that he can take care of the whales instead.
Meanwhile, the crew is taking care of business. McCoy and Scotty trick the head of a plastics factory into giving them the raw materials needed for the tank, while Uhura and Chekov have successfully located a nuclear reactor in a naval vessel.
When Uhura and Chekov perform their heist, however, things go wrong. Although Uhura makes it back to the ship, Chekov is arrested by the Navy and injured in a subsequent escape attempt. He ends up in a coma and is brought to a local hospital.
The next morning, Gillian learns that the whales were released early. They're already gone. Furious, she heads to Golden Gate Park, where Kirk told her he was staying. The crew beams her aboard the ship and reveals the whole insane truth to her.
Before they can snag the whales, however, they must get Chekov out of the hospital. McCoy, Kirk, and Gillian rush over in disguises and smuggle him out, and McCoy easily heals their wounded comrade.
Finally, they pick up the whales, who are currently being chased by a group of whalers. Those schmucks don't have a chance against our crew's futuristic technology, clearly.
And now...we go back to the future. We've been waiting so long to say that.
The crew arrives mere moments after they left, with the probe still in the middle of its assault. After they crash-land into the water, Kirk releases the whales, and they start singing their song. The probe responds in kind before slowly backing away from Earth. It leaves.
Their mission complete, the crew must now face their punishment. As it turns out, all charges are dropped except for one against Kirk. His punishment is to be demoted from admiral to captain, and he's given control of the newly rebuilt Enterprise—which, of course, is no punishment at all. It's exactly what the guy wants.
In the film's closing moments, the crew reassembles aboard the latest and greatest edition of the USS Enterprise and prepares for yet another adventure into the wild unknown.