In Piqua, Ohio, George Beard (Kevin Hart) and Harold Hutchins (Thomas Middleditch) are two fourth-grade friends and next-door neighbors who often express their sense of humor at their school, bringing joy and laughter to Jerome Horwitz Elementary School. The duo frequently prank the cruel teachers at the school, especially the ill-mannered misanthropic principal, Benjamin “Benny” Krupp (Ed Helms), which puts them at odds with him. The duo also create comic books about Captain Underpants, a superhero who fights crime while wearing only underwear and a cape. They sell these to their schoolmates through a comic company called Treehouse Comix Inc, housed in their treehouse. George and Harold’s pranks come to an apparent end after they tamper with a toilet invention called the Turbo Toilet 2000 made by the school’s local snitch, intellectual Melvin Sneedly (Jordan Peele), which launches it into chaotic malfunction, resulting in the school’s boring Invention Convention getting turned into a boisterous and upbeat dance party inside the gymnasium, involving toilet paper, and the song, “Think” (covered by Adam Lambert). Melvin snitches on George and Harold, and as evidence, shows Krupp footage of George and Harold tampering with the Turbo Toilet 2000, recorded by an invention Krupp asked Melvin to come up with himself, called the Tattle Turtle 200, a stuffed turtle with a nanny cam hidden inside of his head. This causes Krupp to decide to put the boys in separate classes and annihilate their friendship.
To prevent this, George hypnotizes Krupp with a 3D Hypno Ring he received out of a cereal box; the boys first order their principal to act like a chicken and a monkey. Finally, they see that Krupp bears a resemblance to Captain Underpants without his toupee and command him to be Captain Underpants. The boys soon learn the severity of their acts when Captain Underpants begins causing trouble around Piqua and take him to their treehouse. There they discover that they can turn Captain Underpants back into Krupp by splashing water on him and can turn him back by snapping their fingers. Believing that Krupp will continue with his plan to separate them, they decide to settle with Captain Underpants but insist that he be dressed up as Krupp under the pretense of a secret identity to which Captain Underpants agrees. His sudden personality change even manages to attract the attention and affection of the school’s shy and clumsy lunch lady, Edith (Kristen Schaal).
Just when George and Harold believe that their troubles have ended, Jerome Horwitz Elementary School is visited by an odd, German-accented scientist named Professor P. (Nick Kroll). Captain Underpants (disguised as Krupp) hires him to be a new teacher, but George and Harold are suspicious of him. As it turns out, Professor P. is seeking to get rid of laughter altogether, due to the fact that people have made fun of his full name (Professor Pee-Pee Diarrheastein Poopypants, Esq.) for years. He recruits Melvin to help him and soon finds out his brain is incapable of having fun.
Soon, Professor Poopypants tries to take over the town with a giant version of the Turbo Toilet 2000, fueled by the school cafeteria’s rotten leftovers left out by Edith, and uses Melvin’s brain to turn the children into glum, humorless zombies. Captain Underpants tries to stop the villain, but due to having no actual superpowers, is effortlessly defeated and thrown into the toilet. George and Harold are captured and turned into zombies, but begin laughing upon Professor Poopypants mentioning Uranus as one of the planets he would remove laughter from later. Due to this, they are able to break the trance and escape when their excessive laughter damages the Turbo Toilet 2000’s computer. Upon consuming the mutated leftovers, Captain Underpants acquires superpowers and, with George and Harold’s help, defeats and shrinks Poopypants, though he escapes shortly thereafter on a bee.
Knowing that they cannot control Captain Underpants, George and Harold destroy the Hypno Ring in an attempt to permanently change him back into Krupp. Feeling that Krupp would be nicer if he had friends, the boys set him and lovesick Edith up on a date, thus making Krupp have a change of heart; he returns the comics he took away from George and Harold, and even admits their comics are funny. However, the toxic waste from the Turbo Toilet 2000 transforms all the toilets into vicious monsters that attack the restaurant at which Mr. Krupp and Edith are dining. Upon snapping his fingers (accidentally), Mr. Krupp once again becomes Captain Underpants and flies away, carrying George and Harold away to help him fight them, much to Edith’s surprise and admiration. As this happens, George says he thought destroying the Hypno-Ring would get rid of his powers and Harold exclaims his catchphrase said at the end of every Captain Underpants book, save the last, ‘here we go again!’. Then, Captain Underpants stops in front of the moon to say “Tra-La-LAAA!!!” one last time to end the movie.
In a mid-credits scene, George and Harold realize that the secretary, Miss Anthrope (Grey Griffin), who they put on the phone before by faking a $1 billion contest has been on hold for the whole film. After Miss Anthrope accidentally hangs up and gets mad, George and Harold make a new comic based on her reaction titled “Captain Underpants and the Attack of the Stuck On Hold Woman”.