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 plans to turn them over to the warden, who will execute them both for attempted escape and give Martia a full pardon.
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. The president welcomes the group while Chang's ship approaches Khitomer's orbit, and cloaks. The president starts off the conference giving a speech about progress.
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 takes heavy damage and the shields are quickly collapsing. The Enterprise begins reversing, momentarily confusing Chang, wondering if the Enterprise detects them. The Bird-of-Prey fires again, causing more damage to the Enterprise while the Excelsior races toward the Enterprise.
In the meeting hall on Khitomer, Azetbur gives an impassioned speech about her father's efforts to secure peace. One of the Klingons in the audience leaves the meeting hall, carrying a case. The Bird-of-Prey fires again on the Enterprise, now destroying their auxillary power. 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 to detect the gas exhaust from the cloaked Klingon ship.
Spock and McCoy head down to the torpedo bay to modify a torpedo to detect the gas. The Klingon with the case takes up a position above the speaker's podium and cuts out a hole in the glass, revealing the president. Excelsior arrives shortly after the battle begins and provides distraction for Chang, who immediately orders open fire on Sulu's ship. The Bird-of-Prey continues firing several more severely damaging blasts at the two Federation ships while Spock and McCoy equip a photon torpedo with the components.
Just as Scotty announces the shield is collapsing, another blast hits the Enterprise, ripping through the hull. The Klingon hiding above the conference assembles a Klingon sniper rifle. 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.