In a flashback to 1947, a P.I. named Joe Flynn (played by Castle) stops by the Pennybaker Club, asking about a woman named Vera Mulqueen. The bartender points out Vera (played by Beckett) standing across the room, and the two share a moment. In the present, meanwhile, the building is now the scene of a homicide. The victim is Stan Banks, dead from a single gunshot. Ryan and Esposito go check out an inn where the victim was staying, where the manager shows them Stan's room, saying that before Stan died, he'd been bragging that his ship had finally come in. Meanwhile, at the precinct, Beckett and Castle speak with Stan's estranged wife. According to her, Stan had caught the treasure-hunting bug, and it had only gotten worse after he'd watched a documentary on famed treasure hunter Clyde Belasco (more on him later). The wife adds that lately, Stan had been obsessed with something called the Blue Butterfly. Later, Castle and Beckett are going through the victim's things, when they find an old journal belonging to Joe Flynn. Castle decides to take it home, rationalizing that it may be relevent to the investigation. That night, he reads through it, imagining himself and his loved ones as characters from the journal. In a flashback, Joe's secretary (played by Martha) shows a young woman (played by Alexis) into Joe's office. She introduces herself as Sally Scofield, and says she wants to hire Joe to find her sister, Vera Mulqueen. Only, she says, her sister can't know she's looking for her, as there was some bad blood back home. Joe later goes sniffing around at the Pennybaker Club, where singer Betsy Sinclair (played by Lanie) is up on stage. As in the opening scene, Joe asks the bartender about Vera, before sharing a moment with the woman in question. As it turns out, though, she's the girlfriend of Tom Dempsey, a mob boss who owns the club. Dempsey notices Joe looking at his girl, and sends two of his goons (played by Ryan and Esposito) to rough him up. Afterwards, Vera asks if he's okay, and that's when he notices a butterfly-shaped necklace made up of blue diamonds around her neck. Back in the present, Castle realizes Vera's necklace was actually the Blue Butterfly Stan was looking for.
The next day, Castle tells Beckett and Ryan his revelation, explaining that the necklace disappeared in the 1940s and was rumored to be hidden somewhere in the Pennybaker Club. He suggests they check Tom Dempsey's office, as the necklace used to be kept in Dempsey's safe. Unfortunately, they find the safe empty, but Castle insists that Dempsey must have kept a second, secret safe for his "extra special" valuables. In speculating where the secret safe was hidden, Castle recounts the story of Joe and Vera, explaining that the two fell in love within five days of meeting each other but that they had to sneak around since she was still Dempsey's girl. In a flashback, Betsy Sinclair covers for the lovebirds by telling Dempsey's goons that Joe is with her. She then tells Vera to wise up, reminding her what will happen if Dempsey catches them together. That's when Joe and Vera make a plan to run away, intending to sell the necklace for the money to get away from Dempsey. Vera says she used to work at the club as a cigarette girl, and that she knows where Dempsey's secret safe is. Back in the present, meanwhile, Castle explains that that was the last entry in the journal, much to Beckett's consternation. Thankfully, though, she manages to uncover a second safe hidden behind some wooden paneling in Dempsey's office. She and Castle find it empty as well, and surmise that Stan found the necklace and was then killed for it. Meanwhile, Ryan and Esposito interrogate Ray Horton, a bookie Stan owed money to. Ray explains that he invested money in Stan's treasure hunt, and thought that Stan had played him. Then, two days ago, Stan had claimed to have found a man with a missing piece of the puzzle, and even though Ray has no idea who that man is, he speculates that that's who had killed Stan. Later, Ryan informs Beckett and Castle that Ray alibied out, and that ballistics just confirmed that the gun used to kill Stan was also used to kill Joe and Vera in 1947.
Ryan explains that Joe and Vera's remains were found in Joe's car, which had been set on fire after the two had been shot. The police had suspected Dempsey, but he couldn't have shot Stan because he'd died of a heart attack four months after Joe and Vera had been killed. As Castle goes with Ryan to retrieve the case files from 1947, Esposito informs Beckett that treasure hunter Clyde Belasco had bought all of Dempsey's guns at an estate sale, and that Clyde had been looking for the Blue Butterfly for fifteen years. So, Beckett later interrogates Clyde, who says that Stan approached him, asking for all of his research on the Pennybaker Club. He refused, adding that Stan had had to leave quickly, as he thought he was being followed by a white Mustang. Meanwhile, Castle and Ryan are going through the case files, when Castle finds a statement from Joe's secretary, Florence Kennard. In a flashback, Joe and Vera are in his office, Joe telling Vera that they'll never be able to crack Dempsey's safe. Instead, Joe has come up with a plan: Vera is to wait until Dempsey's goons are preoccupied with a prizefight on the radio, then excuse herself and walk right outside wearing the Blue Butterfly, right into Joe's waiting arms. Just then, Florence enters, and tries to talk Joe out of running away with Vera. She adds that their relationship is based on a lie, and that's when Joe comes clean that he was hired by Vera's sister to find her. Only, Vera says, she doesn't have a sister. Back in the present, Ryan ponders what Sally must have been up to posing as Vera's sister, while Castle gets excited about the "classic film noir twist" the case has taken. That night, at the precinct, Esposito gets a call that the owner of the white Mustang that was following Stan was just caught breaking into Stan's room at the inn. He and Beckett go to arrest the intruder, only to find he looks just like the late Tom Dempsey.
Turns out, the intruder is Dempsey's grandson, Tom Dempsey III. He says Stan had approached him, claiming to be a biographer wanting to do a story on Dempsey Sr. Stan had promised to focus only on the good, so Dempsey III had given him access to his grandfather's old things. It wasn't until Betsy Sinclair's funeral a couple of weeks ago that he figured out Stan was just another lowlife treasure hunter. He insists, though, that he didn't kill Stan. The next day, Ryan informs the others that Dempsey III's alibi checks out. So, Castle instead points them in another direction: Jerry Maddox, a bartender for the Pennybaker Club and the last living link to the Blue Butterfly. Beckett and Castle later visit Jerry Maddox and his wife Viola. Jerry says Stan approached him at Betsy's funeral, asking about the Blue Butterfly, but insists he wasn't much help since he was just a bartender back then. Castle then asks about Sally Scofield, and Jerry reveals that before Dempsey started dating Vera, his arm candy was a redhead named Priscilla Campbell. Sally, as it turns out, was Priscilla's daughter, and had blamed Vera for Dempsey dumping her mother, causing her mother to commit suicide. According to Jerry, Sally walked into the club the night of Dempsey's funeral, smugly claiming that she was free. Back at the precinct, meanwhile, Ryan and Esposito interrogate a homeless man, West Side Wally, who had been squatting at the club, hoping he might have seen something that could help them. Wally tells them he was nowhere near the club during Stan's murder, as some professor-looking type had paid him to get lost. When Esposito shows him a photo, Wally positively identifies Clyde Belasco as the guy who'd paid him.
Later, Beckett and Castle interrogate Clyde, who reluctantly admits he had staked out the club, waiting for Stan to show up. He'd realized Stan had gotten closer to finding the Blue Butterfly than he himself had ever gotten in fifteen years, and had therefore intended to steal the necklace and claim the glory for himself. According to Clyde, Stan had emerged with the Blue Butterfly, but then Clyde had been chloroformed and when he came to, Stan was dead and the killer had already taken the necklace. After the interrogation, Castle expresses disappointment in the turn the case has taken, since he had hoped to solve Joe and Vera's murder as well. He says there's something they're missing, and recounts Joe's description of Sally, right down to the T-strap shoes she was wearing. Suddenly, Beckett figures out another piece of the puzzle. She points out that in the crime scene photo of Joe and Vera's murder, there's a T-strap shoe on the ground next to Joe's car, adding that Vera would've been wearing an elegant dress and heels that night. This means that the dead woman was Sally, not Vera, and that Jerry Maddox had lied about seeing Sally months later. Beckett and Castle go confront Jerry and his wife, realizing that the two are actually Joe and Vera.
As Frankie, a home health aide, listens in, Castle and Beckett question Joe and Vera about Stan's murder. They admit Stan had figured out the truth and had bullied them into giving up the location of the Blue Butterfly, but insist that they didn't kill him. When Castle reveals Stan was killed using the same gun that had killed Sally, Vera informs them that they keep the gun in a china cabinet drawer, and that's when Frankie goes for the gun, admitting that he killed Stan. Turns out, Frankie's mother had been Joe's secretary, and he had put the pieces together six months ago. Since then, he had taken a job working for Joe and Vera, hoping to slowly earn their trust and learn the location of the Blue Butterfly. After Stan had bullied the location out of them, Frankie had followed him, intending only to steal the necklace, but instead, wound up killing him on accident. Frankie is arrested, and taken away in cuffs. That night, Beckett shows Castle the Blue Butterfly, which she found in Frankie's apartment. According to an appraiser, though, the necklace is a fake. Castle hopes it means that the real one was switched out years ago, but Beckett reminds him that it doesn't change the fact that they still have one more murder to close. So, they head back to Joe and Vera's apartment, asking them what happened the night Sally was killed. Through flashback, Joe and his wife explain that Vera had walked out with the Blue Butterfly like Joe had planned. Only, they were then confronted by Sally and her husband Lenny, who had hired Joe to get Vera away from Dempsey so Sally could enact her revenge. Joe and Lenny had fought for a bit, and in the chaos, Sally had accidentally shot her husband. Vera then struggled with Sally for the gun, but it went off, killing Sally. It was then that Joe came up with a plan to fake their deaths using Sally and Lenny's bodies. After listening to their story, Beckett decides to keep their secret, pointing out that Sally and Lenny's deaths were self-defense. Castle, however, has to ask about the Blue Butterfly and what they did with it. In yet another flashback, Vera realizes the necklace is cursed, and she and Joe decide to hide it behind a brick in an alleyway wall. Back in the present, Joe and Vera insist they've had a long, happy life together without the Blue Butterfly. Beckett contemplates telling them the truth about the necklace, but Castle counters that their life is one everyone dreams of and that they shouldn't ruin it for them. In one final flashback, Joe and Vera watch Joe's car burn with Sally and Lenny's bodies inside. Vera asks Joe to tell her that he loves her, and he replies, "Always."