Star Trek IV : The Voyage Home

The crew of the Enterprise has been ordered to return to Earth for a trial, most likely their court martial. As Kirk flies back to Earth in his Klingon Bird-Of-Prey, dubbed "Khan's Bounty," the crew receives a distress call from Earth, saying that no starships should come close to Earth, because an alien probe has rendered everything in its path inoperable, and it is now starting storms on Earth.
Spock determines that the signal the probe is sending out is meant for humpback whales, and only they can respond to the signal. Kirk and crew decide to travel back in time, back to 1986, where they attempt to find humpback whales to satisfy the alien probe's interests.
After many intriguing, exciting and comical adventures in San Francisco of 1986, Kirk returns to the 23rd Century with the two whales, and the probe leaves. Due to their heroic efforts while saving Earth from the probe, all the charges against the crew of the Enterprise are dropped, except for a demotion for Admiral Kirk, down to Captain. And there is another reward, as well. Sulu gets his own ship to captain, the USS Excelsior, and Kirk gets a newly refurbished Enterprise-A.