Boris the Animal (Jemaine Clement), last of the Boglodite race, escapes from Lunar-Max Prison on the Moon. He wants vengeance on Agent K (Tommy Lee Jones), who shot off his left arm and jailed him in 1969. Boris confronts K and his partner Agent J (Will Smith) while on a case, telling K that he is "already dead," and flees. J searches the MIB database when K refuses to discuss his past, and discovers Boris committed several murders in 1969 before being captured by K, and that K deployed an "ArcNet" shield around Earth in July of the same year that prevented a Boglodite invasion, thus starving them to extinction. Agent O (Emma Thompson), the new head of MIB after Zed's passing, confronts J and tells him not to probe deeper. That night as he talks to J on the phone and awaits Boris to arrive to attack him, K vanishes, and only J remembers he ever existed when he shows up at MIB looking for him. O shows J a statue to K, killed by Boris in 1969, and tells J that his chocolate milk craving and headaches are a result of a 'temporal fracture' of time travel. At this point, the Boglodites start to invade Earth. J learns that Boris time-jumped to July 16, 1969, killed K, and prevented the ArcNet from being installed. J jumps off a skyscraper with another time travel device in order to travel back to July 15, 1969 and save K.
In 1969, J heads to Coney Island, where the first murder took place. He finds 1969 Boris and attempts to shoot him but is knocked out by 1969 K (Josh Brolin), 29 years old and much more light-hearted than the K J knows in 2012. J is taken to 1969 MIB headquarters for questioning, and finds K flirting with 1969 O (Alice Eve). Suspicious of J, K prepares to neuralyze J until J tells the truth, convincing K to accept his aid in capturing Boris. The two follow clues to Griffin (Michael Stuhlbarg), a fifth-dimensional being who sees multiple timelines simultaneously. At The Factory studio party hosted by Andy Warhol (Bill Hader) aka Agent W, 1969 Boris attacks. Griffin flees, after promising a gift and a miracle game. J remembers a miracle game Griffin said that will take place soon at Shea Stadium. They arrive there and find Griffin, who shares his timeline vision of "his favorite moment in human history", when the losing NY Mets win the World Series due to a series of cosmic coincidences aligning at once. Before Griffin can give them the ArcNet, he is kidnapped by 1969 Boris. J and K pursue him and rescue Griffin and the ArcNet, but 1969 Boris escapes and is met by his 2012 counterpart.
J, K, and Griffin jet-pack to Cape Canaveral, Florida, where Apollo 11 prepares to launch, as they need to attach the ArcNet to the rocket so it can deploy once in space. The military stops them, but Griffin shows the skeptical colonel the future, convincing him how important the agents are, and he assists them in reaching the launch site. As the agents climb to the top of the rocket supports, both 1969 Boris and 2012 Boris attack them, J battles 2012 Boris as K battles 1969 Boris. Using his time travel device to relive Boris's attacks, J defeats him and knocks him off the supports. K shoots off the left arm of 1969 Boris, knocking him off the rocket, and the ArcNet is attached and deployed successfully as Apollo 11 launches, 2012 Boris being incinerated by the exhaust. K and J retreat to safety, when 1969 Boris attacks the colonel, mortally wounding him before K kills 1969 Boris, remembering J's advice to not arrest him. The colonel's young son runs to his father's side but is stopped by K, who neuralyzes the boy and tells him his father is a hero. J, hidden nearby, realizes the boy is his own younger self, the colonel Boris killed being his father, and that K has been watching over him all his life.
J returns to 2012, joins K alive at a diner for pie, and subtly thanks him for all his care, and learns that by Boris's death, the future has remained intact as he remembers it. After they leave, Griffin, previously unseen sitting on a nearby stool, says "This is my new favorite moment in human history. Unless this is the one where K forgot to leave a tip." Griffin looks up and the camera shows a meteor falling to earth. K returns to tip and disaster is averted as a satellite collides with the meteor. Griffin smiles and says, "That was a close one".