Bashir is in the holosuite playing out a fantasy with himself as a secret agent. Garak intrudes and convinces Bashir to let him tag along. Meanwhile, Captain Sisko, Worf, Dax, Major Kira, and Chief O'Brien are on a runabout, returning to Deep Space Nine. As they pull up to the station they find that their ship has been sabotaged and that a warp core breach is imminent. Eddington transports them out, but the ship is destroyed during transport and the five crew members are trapped in the transporter buffer.
Eddington stores their patterns while he repairs the transporter, but doing so uses almost all of the station's memory, putting many station systems off-line. Their physical patterns end up in the computer controlling the holosuite, where they appear as characters in Bashir's program.
Bashir is startled to see Major Kira appear in his program as a lingerie-clad spy with a Russian accent and bombs hidden in her earrings. She introduces herself as Colonel Anastasia Komananov, KGB. She appears to believe she is the character and has no idea who "Kira" is. Bashir and Garak are notified by Eddington that they must not shut the holosuite down, leave the program, or allow any of the characters to die. They are forced to proceed with the story, gambling with the crew's lives.
Anastasia delivers Bashir's assignment. A megalomaniacal scientist named Dr. Noah is planning to take over the world. He has built massive lasers that will cut into the Earth's crust, releasing magma such that the tectonic plates will sink and the planet's oceans will rise over all the land area except the top of Mount Everest, where he has his base. Noah has recruited top scientists from around the globe to assist him in his devious plan. Bashir has orders to rescue one of the scientists, beautiful and shy geologist Professor Honey Bare (Dax), from Noah's clutches.
Complications arise when Bashir's nemesis, Falcon (O'Brien), breaks into his townhouse and pulls a gun to assassinate Bashir. When Anastasia takes him down and prepares to put a bullet in his head, Bashir stops her, since if she kills O'Brien's character, his pattern could be lost from the buffer.
Meanwhile, Eddington is working with Quark (owner of the holosuites) and his brother Rom (the technician who maintains them) to develop a way to bridge the missing crew's patterns from the holosuite systems to a compatible transporter. One of Rom's ingenious technical solutions involves a spatula with the correct physical properties.
Bashir, Garak, and Komananov track down an associate of Dr. Noah at a casino nightclub in Paris. The associate, Duchamps, is Worf in a white tuxedo, blowing smoke rings. He informs Bashir that the price of an audience with Dr. Noah is more than he could possibly afford. Bashir indicates the stack of cash in front of Duchamps, and proceeds to win it all in a flawless night of cards. Duchamps agrees to let Bashir and associates see Dr. Noah, and he knocks them all out with a puff of powdered drugs.
They awaken in Dr. Noah's lair at the pinnacle of Mount Everest. Noah (Sisko) sweeps into the room and shows off his control panel, complete with the big red button he will push when it is time to wipe out the population of Earth to make way for his regime. His timid assistant, Professor Honey Bare, does calculations in the background. She casts a shy glance at Secret Agent Bashir, and he notices.
Dr. Noah has Bashir and Garak taken below ground, to one of the laser rooms, where they are handcuffed to a laser. They are left to die when the laser is activated and the cavern fills with magma. As the time ticks down, Bashir notices Professor Bare performing a last check of the machinery before the place blows. He calls to her and flirts for a bit, and she slips him a key and hurries out. Bashir unlocks the handcuffs and he and Garak search for a way out of the cavern.
Garak has had quite enough of this holoprogram where all the safeties are off and his life is very much in danger. He ignores Bashir's warnings. Before he can call for the holosuite exit, Bashir grazes him with a genuine bullet, shocking (and impressing) Garak, who decides to stick with him. Bashir explains the ending of the program. Once the hero defeats Dr. Noah, he will escape with either Colonel Komananov or Professor Bare; however, the other must die. In order to save both Kira and Dax he must invent a new ending for the program.
Bashir bursts into Noah's study and hits the button. The room's occupants gasp as they realize he just annihilated the entire population of Earth. Dr. Noah is not, however, prepared to spare Bashir, and just as he is about to execute Bashir, Eddington is able to transfer the crew's patterns into the computers aboard the Defiant. They are then simply beamed aboard, returning to their normal selves.
In the holosuite, Bashir and Garak end the program with relief: Bashir "saved the day" by "destroying the world", Garak notes; Bashir jibes Garak that they never taught him that in the Obsidian Order.