Milo, a very bored little boy, receives an unusual package one day: a make- believe tollbooth. When he drives through it in his electric toy car, he is suddenly transported to the Lands Beyond, a fantastic world of imagination. On his way to Dictionopolis, one of the country's two capitals, he meets Tock, the watchdog who joins him on his journey. In Dictionopolis, Milo meets King Azaz who presides over the world of letters and words. Azaz sends Milo on a mission to rescue two princesses, Rhyme and Reason, who are imprisoned in the Castle in the Air, which floats hundreds of feet off the ground. Milo and Tock leave Dictionopolis with a new companion, the Humbug, whom Azaz has sent along as a guide. The three head toward Digitopolis where they hope to persuade the Mathemagician to release the princesses.

On their way to Digitopolis, Milo, Tock and the Humbug encounter all sorts of unusual people and places. Just outside Dictionopolis they stop at Point of View, where they meet Alec Bings, a little boy who floats above the ground because he has not grown down to it yet. In his family, everyone's head stays at exactly the same height their entire lives and their legs grow down until they touch the earth. The travelers then proceed past the twin cities of Reality and Illusions and come upon Chroma and his symphony of color. Milo watches in wonder as Chroma conducts the orchestra through the colors of the sunset and, once Chroma has gone off to bed, decides to try to conduct the sunrise himself. This proves to be more difficult than Milo thought, and soon he has made a complete mess of the colors, which he manages to fix just moments before anyone notices.

The exhausted Milo then leads his friends towards the Valley of Sound, where they meet Dischord, a fake doctor who deals in noises, and his sidekick Dynne, a monster made of smoke. Once the travelers escape the doctor and his horrible racket, they find themselves in the Valley of Sound, which turns out to be completely silent. They meet the Soundkeeper who has withheld all the sounds of the Valley because people have stopped appreciating them and instead gave business to Dischord and Dynne. Milo steals a sound from the Soundkeeper's palace, which the people of the valley use to break open the sound vault.

After helping save the Valley of Sound, Milo and his friends continue on their way to Digitopolis, taking a short detour to the Island of Conclusions, to which they magically jump after making assumptions about their trip. They swim back to shore through the Sea of Knowledge and find themselves on the outskirts of Digitopolis. There they meet the Dodecahedron, a man with twelve faces, each of which expresses a different emotion. The Dodecahedron takes the travelers to see the Mathemagician, after giving them a tour through the Numbers Mine, where digits are pulled from the earth like jewels. Milo manages to trick the Mathemagician into agreeing to release the princesses and finds out that he must climb through the Mountains of Ignorance to reach the Castle in the Air.

Although they are afraid of the demons they might encounter, Milo, Tock, and the Humbug head into the Mountains of Ignorance. They meet the Everpresent Wordsnatcher, a dirty little bird who twists their sentences into his own meanings, the Terrible Trivium, a man with no features on his face who stalls the travelers with meaningless busywork, and the Demon of Insincerity, who tries to trick them into leaving the path to the castle. Fortunately, Milo has learned a great deal from his travels in the Lands Beyond and manages to escape each of these demons and make his way to the unbelievably tall staircase to the Castle in the Air. After climbing to the top, the three travelers encounter a final demon, the Senses Taker, who demands all sorts of trivial information and bogs them down in meaningless questions. Milo's sense of humor, the one thing the Senses Taker cannot take away, helps him laugh his way past the demon and up to Rhyme and Reason.

The two princesses are thrilled to hear that Azaz and the Mathemagician have agreed to release them. Riding on Tock's back, since time flies, they soar over the Mountains of Ignorance and land in the midst of a hoard of demons. When it seems that all hope is lost, the Armies of Wisdom, led by Azaz and the Mathemagician, suddenly arrive and drive back the demons. The two leaders welcome the princesses and begin a celebration to mark their return.

Milo himself must also return home and says his goodbyes to all the friends he made in the Lands Beyond. He returns to his bedroom to find that only a few minutes have passed. The next day, he hurries home from school with dreams of further adventures only to find the tollbooth gone. All that remains is a note that tells him that he has learned so much that he should be able to find his way to all sorts of fantastic lands without the help of the tollbooth. Milo realizes that there are all sorts of fantastic adventures to be had anywhere, even in his own bedroom.