Data is excited about his friend Keiko's upcoming wedding to Chief O'Brien, where the android will be giving the bride away. When the bride succumbs to jitters and calls the wedding off, Data applies android logic, and decides that since O'Brien loves Keiko, if calling off the wedding makes her happy it will make O'Brien happy. Of course, the heartbroken groom's reaction to Data's news quickly reflects otherwise. Data's confusion is compounded when Geordi assures him that the wedding will proceed as planned. With this in mind, he attempts to buy a gift for the couple, and encounters Worf, who informs Data that he will have to dance at the wedding. Data has never danced, so he enlists Dr. Crusher's help — after learning from her file that she was once a tap dancing champion.
In the midst of this pre-wedding chaos, Data must escort aboard the U.S.S. Enterprise the Vulcan Ambassador T'Pel, who is preparing to negotiate a treaty with the Romulans inside the Neutral Zone. While the Ambassador's curt behavior sets most of the crew on edge, the android remains unaffected by emotions. Meanwhile, O'Brien asks Data to convince Keiko to go through with the wedding, and Data's lack of understanding soon upsets her as well. Counselor Troi is unable to help him see the reason for his friend's behavior. Later, T'Pel summons Data to her quarters, where she asks him to reveal secret defense information. He refuses to surrender it on the grounds that the Ambassador does not have proper authorization.
Although he masters tap dancing in seconds, Beverly has some difficulty teaching Data to dance with a partner, but eventually he begins to catch on. Some time afterward, the U.S.S. Enterprise meets a Romulan warbird, and despite Picard's unease about the situation, the crew begins to transport T'Pel aboard. However, something interrupts the transporter signal and the Ambassador is killed.
Finding no flaw in the transport system, Data mimics the tactics of Sherlock Holmes, who, like Data, relied primarily on logic. The android detective discovers that T'Pel was not really killed. Using similar equipment, the Romulans beamed her off the ship themselves and left behind genetic compounds designed to fool the crew into thinking they killed her.
Picard confronts Mendak, the Romulan commander, with this information and learns that T'Pel is actually a Romulan spy. After a tense standoff, the U.S.S. Enterprise heads home. With the danger now passed, Data approaches Keiko to make amends. She informs him that he did not offend her and that the wedding will continue as planned after all. Data soon walks his friend down the aisle, where she and O'Brien are married by Captain Picard.