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) immediately 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.