The story opens with an immense explosion somewhere in space. Huge shockwaves radiate out from the blast site. On board the USS Excelsior, Captain Ikaru Sulu makes an official entry in his log, noting that his mission of "cataloging gaseous anomalies in Beta Quadrant" is over and they are returning to Earth. The ship is suddenly struck by one of the shockwaves from the explosion. Sulu orders his crew to restore control to the ship, which is done quickly. Looking over their scanning equipment, the crew determines that the shockwave originated at the location of the Klingon moon Praxis. Sulu remarks that Praxis is the primary source of energy for the Klingon Empire, and orders a message be sent stating he and his crew will assist if necessary. They receive an emergency transmission from Praxis showing a Klingon worker consumed in flames. A second message comes from Brigadier General Kerla that acknowledges the explosion (he calls it "an incident") and that they do not require assistance from the Federation. He also commands them to stay out of the Neutral Zone. When one of the crew asks if they should report the incident, Sulu replies "Are you kidding??"
On Earth, Captain James Kirk, Dr Leonard McCoy and Engineer Montgomery Scott attend a top-level meeting of Starfleet. They are told almost immediately that the Klingon Empire "has roughly 50 years of life" remaining. Charge of the meeting is turned over to the Federation's special envoy, Captain Spock. He tells the committee that the explosion of Praxis two months earlier has caused an environmental catastrophe on the Klingon homeworld of Q'ono'S (Kronos). Pollution of the planet's ozone layer has left Klingon civilization with only 50 Earth years of oxygen. The Klingon Empire, due to its enormous military budget, is unable to reverse the devastation and has turned to the Federation for assistance. However, as Spock notes, assistance cannot begin until a treaty has been negotiated with the Federation of Planets to cease all hostilities between the two. Spock, being the Federation's envoy, had been speaking directly with Chancellor Gorkon of the Klingon Empire to open treaty proposals.
The committee is stunned by the news and debates whether Starfleet will be dissolved. Science and exploration will continue, however, military efforts will see a significant reduction. Admiral Cartwright protests, saying that the opportunity exists to "bring them to their knees." Spock counters, saying that a peaceful solution is more prudent. In the midst of the debate, it is announced that Kirk will be sent in the Enterprise to the outskirts of Klingon space to escort Chancellor Gorkon's cruiser to Earth for negotiations. Kirk is wholly reluctant, despite Spock's endorsement of him, saying an experienced ambassador should be sent, however, the council leadership ignores him and closes the meeting.
After everyone has left the meeting, Kirk confronts Spock, demanding to know why Spock chose him to escort the Chancellor. Kirk has a high distrust of Klingons, who were responsible for the murder of his son, David Marcus. Spock believes that Kirk, though an unlikely candidate for the mission, should still go, saying "Only Nixon could go to China." Kirk also mentions that the Enterprise's crew was due to stand down (retire) in a few months.
Kirk gathers his crew and the Enterprise leaves Earth. New to the Enterprise is Lt. Valeris, a Vulcan female officer, who is the first of her race to graduate at the top of her class and has been mentored and sponsored by Spock himself. As the ship races towards the rendezvous point with Gorkon, she and Spock share a ceremonial drink in his quarters and discuss the turning point of Federation relations with the Klingon Empire and their implications. Spock tells her that logic does apply to the events at hand but there must also be some acceptance of faith that the new era will bring peace.
The Enterprise and Gorkon's cruiser, Kronos One, arrive at the meeting point. Kirk hails the Chancellor and invites him and his officers to dinner on the Enterprise that night. Lt. Valeris mentions to Kirk the availablility of an on-board supply of Romulan ale, which she suggests "might make the evening pass more smoothly." Kirk replies, "Officer thinking, Lieutenant." The Klingons are beamed aboard; the Chancellor has brought his daughter, Azetbur, his chief of staff, General Chang and Kerla. Though both sides are initially pleasant toward each other, and a few toasts to the peace accords and Gorkon himself are made over Romulan Ale, the underlying hostility of both sides still permeates the conversation. The Klingons themselves seem particularly fond of Shakespeare; their philosophical arguments about the peace accords are laced with Shakespearean thought. At one point Chang announces that his people need "breathing room", whereupon Kirk mentions that the same thought was expressed by Adolf Hitler in 1939. Azetbur speaks of the Federation being a "homo-sapiens-only" club, despite Spock's presence. Gorkon concludes that there is still much work to do. The Klingons leave and the Enterprise crew (literally) breathes a sigh of relief. Chekov mentions that their visitors had "terrible table manners" and Kirk says their own behavior, as humans, was fairly unacceptable as well.
Resting in his quarters (and making a log note that Romulan ale is now banned from all diplomatic functions aboard the ship), Kirk receives a call from Spock to report to the bridge. Hung over, Kirk meets with Spock, who tells him a huge, unexplained neutron radiation surge has been detected on a scanner. As Spock and Kirk try to find it's origin, Kronos One is suddenly hit by a torpedo blast which appears to come from the Enterprise. The Klingon cruiser is hit again and begins to tumble helplessly, losing thruster power and their artificial gravity. On board Kronos One, two figures, wearing Starfleet space suits and magnetic gravity boots, beam aboard and begin to fire upon the Klingon crew with phasers. Most are killed, one is wounded, losing an arm. The assassins move through the ship, finding the Chancellor's chambers. The two Klingons with him are immediately killed, and the Chancellor is shot through the chest. The assassins walk back to the transporter pads and beam out, trailing some Klingon blood with them.
Chang hails Kirk and immediately accuses him of the attack on the ship. Kronos One moves into an attack positions and activates its torpedo cannon, preparing to fire on the Enterprise. Kirk, knowing that the attack would be deadly and spark an interstellar war, surrenders immediately. He offers to come aboard Kronos One and McCoy volunteers to go as well for medical assistance. As Kirk leaves the bridge, Spock surreptitiously touches his shoulder, placing a small object on his uniform. Kirk and McCoy beam to Kronos One and are escorted by Kerla to the Chancellor, who lies bleeding and dying on the deck. Chang tells them about the assassination and accuses them of lying when Kirk claims innocence. McCoy demands to treat Gorkon and does, however, his unfamiliarity with Klingon internal anatomy prevents him from doing more than reviving Gorkon for a few moments. Gorkon gestures for Kirk to approach him and, putting his hand on the back of Kirk's neck says "Don't let it end this way." He dies. Chang immediately places Kirk and McCoy under arrest for the murder under the Federation's articles of interstellar law.
On board the Enterprise, Uhura reports the arrest. Spock assumes command of the ship and orders a general standing down, knowing they cannot attack Kronos One to rescue Kirk and McCoy. Uhura also receives a message from Starfleet to return to Earth immediately, however Spock, wishing to investigate the attack on Kronos One and Gorkon further, discreetly orders Uhura to report that the ship is experiencing multiple malfunctions and cannot return until they are repaired.
On Earth, the Federation president meets with several other council members about the incident. Among them is the Klingon ambassador, who defends his government's arrest of Kirk. The Klingon ambassador also cites, as Chang did, Federation interstellar law. Vulcan and Romulan ambassadors Sarek and Nanclus agree, as does the president, who does not want to provoke the already delicate relations with the Klingon Empire. A daring rescue plan, proposed by Colonel West, is dismissed by the president as well. In Gorkon's place, Azetbur is appointed chancellor and talks directly to the president, saying Kirk and McCoy will stand trial on Q'ono'S. She also affirms her reluctance to attend the peace accords, but agrees, saying that the location must be kept secret and that any attempt to rescue Kirk and McCoy will be an act of war.
The trial begins; the prosecuting attorney is Chang himself, while Kirk and McCoy are defended by Colonel Worf (a cameo by the character from Star Trek: The Next Generation). Chang delivers the charges, that Kronos One was fired upon, the assassins came from the Enterprise and that Kirk ordered the attack. Though Worf successfully dismisses the final charge, Chang is still able to lay the conduct of the two assassins on Kirk, saying, as captain, he is responsible for the conduct of the crew under his command. Kirk does not deny the charge. When McCoy is questioned about his attempt to revive Gorkon, Chang attacks him verbally, challenging his medical expertise based on McCoy's age. He also cites the fact that McCoy, along with all the other dinner guests, consumed Romulan Ale that may have affected his ability to aid the Chancellor. The most damning evidence that influences the trial is Kirk's own words, possibly stolen from his personal log, where he stated "I've never trusted Klingons, and I never will. I can't forgive them for the death of my boy." The jury and court are swayed and Kirk and McCoy are found guilty. They are sentenced to the Klingon penal colony, Rura Pente ("The Devil's Graveyard") a remote and frozen asteroid deep in Klingon space, where they will mine dilithium for the rest of their lives along with 1000s of other Klingon prisoners.
On the Enterprise, the bridge crew, at Spock's request, watches video of the torpedo hits to Kronos One. They determine that, though the memory banks of Enterprise show two torpedoes had been fired and that all the torpedoes they were carrying before the attack have been visually accounted for, the shots must have come from another ship. The only ship capable of remaining undetected would be one with a cloaking device, a Bird-of-Prey, which cannot fire while cloaked. Spock ascertains, through the logical statement "once you eliminate the impossible, whatever remains, however improbable, must be the truth" that the Bird-of-Prey that fired on Kronos-One can fire while cloaked. After further deduction, the crew knows what they must search for: the two pairs of magnetic gravity boats worn by the assassins. The crew begins to search every corner of the ship; as they do, they are continually contacted by Starfleet and ordered to return to Earth. Spock tells Scotty to report that the Enterprise is experiencing a warp drive malfunction. When Scotty begins to protest, Spock slyly tells them they need more time to search the ship. Scotty heartily says it could take "weeks" to repair. Later, Chekov finds dried Klingon blood on the transporter pads and Spock says they will also search uniforms. A pair of gravity boots are found in the locker of Crewman Dax, however his feet are largely different from human feet so the boots cannot be his.
Kirk and McCoy arrive on Rura Penthe. They are told that nothing can survive on the surface due to extremely cold temperatures, and a prisoner is cruelly thrown outside to prove the warden's point, freezing in mere minutes. A magnetic field above the asteroid prevents any unauthorized beaming to a ship. In the depths of the mine, Kirk is threatened by a large alien who demands his coat. Another prisoner, Martia, gets the thug to back off. Later, Kirk finds himself in a fight with another huge alien who is easily winning the battle. Kirk kicks the beast in the knees and it falls down defeated. When he remarks he was lucky, Martia tells him that he kicked the creature's in the genitals. Later, after they go to bed, McCoy relates their plight to the Kobayashi Maru test. Kirk theorizes that the incidents that led them to their imprisonment may have something to do with others who fear the peace accords with the Klingons. Suddenly, Martia appears and offers Kirk the chance to escape. The next morning they go to a meeting place arranged by Martia but do not see her. However, she is there, in the disguise of a large, hairy & ape-like alien. She later changes to the form of a young human girl, allowing her to slip out of her shackles. She takes Kirk and McCoy through a hidden tunnel that leads to the frozen surface of the planet and gives them warm winter clothing. They begin a lengthy march that will put them beyond the magnetic field covering the prison.
Back on the Enterprise, the signal from the device that Spock secretly placed on Kirk, a viridium patch, appears on a scanner and they set a course for Rura Penthe. In order to evade Klingon security outposts, Uhura, unable to use a universal translating device, must speak in Klingon. She is able to fool a sleepy guard at an outpost and the Enterprise continues to Rura Penthe.
Martia provides a flare for building a fire. Kirk says he recognizes her as a "chameloid", a shape-shifting species that were supposed to be mythical. Kirk also hits her, knowing she plays to turn them over to the warden, who will execute them both for attempted escape. Martia changes into a likeness of Kirk himself and the two fight. The warden and several guards appear. The warden vaporizes Martia with a blaster and is about to tell Kirk who's behind the plot to kill him when he and McCoy are suddenly beamed to the Enterprise. The ship streaks away from Klingon space.
Spock brings them both up to date on his theory. As they make their way to the bridge, they find two crewmembers' bodies lying in a passageway, both killed by stun phaser shots at close range. Scotty runs up, having found the missing uniforms with dried Klingon blood, which belong to the two dead men. Kirk and Spock have a quiet discussion and set a trap for the crew members' killer. A shipwide announcement is broadcast, saying statements will be taken from the dead men in sickbay. Their killer goes there and finds Spock and Kirk posing as the corpses. The killer is Valeris and Spock is visibly furious.
On the bridge, Kirk and Spock interrogate Valeris and discover she is part of a conspiracy to sabotage the peace accords and had stood outside Kirk's quarters, recording the log entry used as evidence at his trial. She refuses to reveal the names of her cohorts; Spock performs a mind-meld and finds out that Admiral Cartwright, Romulan Ambassador Nanclus and General Chang are also part of the conspiracy. She does not know, however, where the peace conference will take place. The Enterprise hails Excelsior and Sulu tells them that the conference will be held on the planet Khitomer. Valeris also reveals that there is only one Bird-of-Prey, a prototype. Detecting it will be difficult however Kirk orders a course set for Khitomer, after warning Sulu about the evasive ship. Sulu says reaching them in time will be difficult but he agrees to help.
The peace conference gets underway at Camp Khitomer. Several of the conspirators are present, on of the Klingons leaves the meeting hall and takes up a position above the speaker's podium and assembles a Klingon sniper rifle. Enterprise arrives at Khitomer and is quickly hailed by Chang in the prototype Bird-of-Prey. He taunts Kirk with Shakespearean dialog, saying that Kirk prefers war to peace and opens fire on the Enterprise. Enterprise loses power and its shields quickly. Excelsior arrives shortly after the battle begins and provides distraction for Chang. In the meeting hall on Khitomer, Azetbur gives an impassioned speech about her father's efforts to secure peace. In space, the Bird-of-Prey fires several more severely damaging blasts at the two Federation ships. Spock suddenly has an idea; he mentions that the Bird-of-Prey expels gas as it's exhaust. Uhura suggests they use the equipment they have on board for studying gaseous anomalies and Spock and McCoy equip a photon torpedo with the components. The torpedo is fired and homes in on Chang's ship and scores a direct hit, crippling its cloaking device. Both Enterprise and Excelsior destroy the prototype with photon blasts.
On the planet, the Federation president takes the podium while the Klingon sniper aims his rifle at him. Kirk, having beamed down with Spock, Valeris and Scotty, rushes the stage and pulls the president out of the way just as the sniper shoots. As the sniper, seeking another target, points his rifle at Valeris, Scotty bursts into the room and shoots him. He falls through a glass window and onto the hall floor. The sniper is actually Colonel West, wearing a Klingon mask. Kirk explains that they have evidence of the plot and that those involved were frightened of the potential changes that would result.
Later, the Enterprise and Excelsior head out into space from Khitomer. Kirk makes a last entry in his log, stating that this will be the last voyage of the Enterprise. They communicate one last time with Sulu aboard his ship before he takes a different course. They receive a transmission from Starfleet ordering them to return to Earth. Spock suggests their reply be "Go to hell." Chekov asks for a course heading and Kirk says "Second star to the right and straight on 'til morning." The Enterprise goes to warp and disappears. Before the closing credits role, the signatures of the principle cast members appear on the screen one at a time.