Just moments after Emmet Brickowski (voice of Chris Pratt) and his friends saved their city of Bricksburg, they are visited by aliens from the planet Duplo. This comes just after their real-world builder Finn (voice of Jadon Sand) is told by his father (voice of Will Ferrell) that his little sister is now allowed to play with Legos. After the Duplos threatens to destroy the Lego people, Emmet approaches them with a heart that he builds as a peace offering, only for the Duplo leader to eat it. Lucy, AKA Wyldstyle (voice of Elizabeth Banks) tries to attack, but this just makes the alien scream powerfully enough to shatter windows. The Duplos start to rampage across Bricksburg, causing structures to collapse. Emmet and Lucy get help from Batman (voice of Will Arnett), Unikitty (voice of Alison Brie), Metalbeard (voice of Nick Offerman), and Benny (Charlie Day), but they are outmatched and defeated. Meanwhile, President Business (also Will Ferrell) ditches them to go golfing.
Five years later, Bricksburg has become Apocalypseburg, with everyone adjusting to their new city by being dark, brooding, and edgy. Lucy says that the Justice League - Superman (voice of Channing Tatum), Wonder Woman (voice of Cobie Smulders), Aquaman (voice of Jason Momoa), Green Lantern (voice of Jonah Hill), and Cyborg - went off to fight the Duplos, but they never returned. Batman stayed behind to do a standalone adventure and is now living in a large fortress with Alfred (voice of Ralph Fiennes). Emmet is the only one who retains his cheerful disposition. He joins Lucy with some coffee, but she is too busy brooding. Emmet then mentions having a crazy dream in which he saw a dolphin clock with a time of 5:15, and a black hole opening that swallows all of his friends in an event called "Ourmamageddon". He then shows Lucy that he built them a house just outside of the city, and he brings her over to check it out. While she thinks it's nice, she worries it will attract unwanted attention, and she also thinks Emmet is too childish. Her fears are confirmed when a ship descends toward the city and spots Emmet, Lucy, and Unikitty (who is now huge and goes by Ultrakitty). The pilot fires a heart bomb at the trio, who run away after building an escape buggy. However, they are followed because Emmet puts his blinker on.
They make it to Batman's fortress where they hide from the invader, and Batman attempts to fire at them, but it doesn't work. The invader makes her way in and introduces herself as General Sweet Mayhem (Stephanie Beatriz). She seeks out the leader of the group, and Lucy points Emmet out as "The Special". Mayhem disagrees and doesn't see anything special about Emmet. She proceeds to kidnap Lucy, Batman, Unikitty, Benny, and Metalbeard and take them with her. Emmet tries to get the other citizens to help him save his friends, but they don't want to join him due to him being immature. Emmet sets off on his own to rescue his friends by converting his house into a ship.
Mayhem brings the Master Builders to the Systar System where she lives. She takes them to a planet ruled by the shape-shifting Queen Watevra Wa'Nabi (voice of Tiffany Haddish). Watevra appears like an evil tyrant, but she does her best to persuade the heroes that she is the complete opposite of a villain by singing a song about it. She manages to persuade the others by appealing to their interests (spaceships for Benny, cute stuff for Unikitty, pirate stuff for Metalbeard, and just appealing to Batman's ego). Everyone but Lucy is convinced that she can be trusted. Watevra wants to marry Batman and unite their worlds, which startles him.
Emmet is making his way through space, only to come across a glassteroid storm. Just before he collides with one, he is saved by the super cool Rex Dangervest (also Chris Pratt), flying in a ship shaped like a fist. He brings Emmet on-board and introduces himself as a galaxy-defending cowboy/raptor trainer (in other words, Chris Pratt's most famous roles). Rex tells Emmet his backstory of how he was left trapped under the dryer in Finn's home and was forgotten by his friends, but he managed to pull himself out and become who he is now. He has a whole control center with raptors that he trained. Rex then decides to join Emmet in his quest to save his friends.
The Master Builders are brought to Planet Sparkles in preparations for the wedding. Lucy is given a wash, revealing that the black in her hair is painted, and her real hair is blue. Watevra's assistants - Ice Cream Cone (voice of Richard Ayoade), Banarnar (voice of Ben Schwartz), and Balthazar (voice of Noel Fielding) - try to get Lucy as pumped up as they are by forcing her to listen to the upbeat "Catchy Song". She escapes and finds herself crawling through a vent next to Bruce Willis (voicing himself as a Lego).
At the same time, Emmet and Rex appear on the same planet with other Lego Mini-Figures people. Emmet finds everybody to be overly happy and friendly. The Justice League are there, and Superman is now best buds with Green Lantern (whom he couldn't stand before) and even Lex Luthor (voice of Ike Barinholtz). They also go along and sing "Catchy Song", which Rex finds painful.
Batman and Watevra have a private dinner together. Mayhem scans Batman and detects that he is hiding his insecurities under his ego, which Watevra implies is not unlike her. He admits that he is not looking to get hitched, but Watevra responds that she only said she wanted to marry him to make her real crush jealous. This starts to make Batman walk back on his words, just as Watevra starts to sing a song about why she's not into Gotham City guys. Batman relents and makes an official proposal to her.
Numerous citizens gather on top of a giant wedding cake for Batman and Watevra's wedding. Lucy meets up with Emmet and Rex as they both plan to stop the ceremony by smashing the wedding cake. Rex is suspicious of Lucy and thinks she is brainwashed, but Emmet trusts her. As they proceed with their plan, Lucy runs into Mayhem, and in the confrontation, Mayhem is knocked off a ledge. Her helmet falls off, and her deepened tough voice is gone, and she appears genuinely frightened as she holds on for dear life. She slips but Lucy manages to catch her. Mayhem explains that she and Watevra really aren't bad, and that they just wanted to unite their worlds. This leads Lucy to realize that Rex is the true villain, as he is trying to keep everyone apart. Outside, Lucy watches the ceremony and sees Watevra take her true form - the heart that Emmet built all those years earlier for the Duplos. Before Lucy can stop Emmet, he harnesses his "grown-up" power and smashes the cake, which causes everything to fall into ruin and tear open a hole.
Everything that happens is a result of the real world where Finn's sister Bianca (voice of Brooklynn Prince) has brought Finn's Legos into her room so that they can play together, but Finn is a jerk and he breaks Bianca's creations. Their mother (voice of Maya Rudolph) comes in and scolds them for fighting, and because the Legos hurt her bare feet, she orders the kids to put the pieces away in a storage bin (the black hole). This makes Emmet's nightmare of Ourmamageddon come true, as the kids pick up all the Legos and leave them trapped in the darkness of the storage bin.
After Emmet realizes what has happened, Rex tells him the truth - he is Emmet from the future! On his trip to save his friends, Emmet ended up under the dryer and was left alone, just watching Finn play without him. He became bitter and forced himself out of the dryer where he made a new tougher, mature image for himself and shunned all the cute and childish things he once valued. He made himself a time machine using bits from the DeLorean, Bill and Ted's phone booth, the Tardis, an H.G. Wells contraption, and a hot tub, and he used it to go back in time to find Emmet before he got lost. Since Emmet doesn't agree with his plans, Rex tosses him out of the ship and back under the dryer.
Lucy, Mayhem, and the Master Builders all feel sad and sing about how everything is NOT awesome, but this doesn't mean that it has to be the end for them. In the real world, Finn realizes that he was rotten to Bianca and remembers how much fun they had playing together when they were younger, and he makes amends with her by bringing her the Watevra heart. Meanwhile, Emmet is stuck under the dryer and attempts to free himself, but he has limited movement down there. Rex joins him to fight and keep him there, but now that Finn and Bianca are playing, Lucy is free and she goes to help Emmet, and they use one of Mayhem's heart bombs to defeat Rex. Rex realizes how wrong he was, but now that Lucy has come to save Emmet, it means that Rex won't exist. He starts to disappear but bids farewell to Emmet and Lucy. The two are then reunited with their friends.
Finn and Bianca combine their worlds so that all the residents now live in harmony. President Business returns from his golf trip but gets kicked out of town almost immediately. Lucy rebuilds her and Emmet's home and presents him with a surprise: an original album of "Everything is Awesome". Emmet looks closely and sees Lucy on the cover, and it slowly dawns on him that she was one of the original artists behind the song.