In ancient Basra, a blind beggar begins telling the film's story in flashback, revealing that he is really Ahmad, the young, naive king of Bagdad. Wanting to know more about his people, Ahmad is tricked by Jaffar, his Grand Vizier, into going in disguise into the city. Jaffar then has him arrested and usurps the throne. In prison, Ahmad meets the young thief Abu, who arranges their escape. They flee to Basra, where Ahmad meets and falls in love with the Princess. Jaffar, however, also journeys to Basra, intent on having the Princess for himself.
Jaffar, a powerful sorcerer, provides the toy-obsessed Sultan of Basra with a mechanical flying horse in exchange for his daughter's hand in marriage. The Princess, now in love with Ahmad, runs away, but Jaffar uses magic to blind Ahmad and turn Abu into a dog. She is captured and taken to the slave market, where she is bought by Jaffar's agent. At the palace, though, she falls into a deep sleep and cannot be awakened. Halima, Jaffar's minion, tricks Ahmad into awakening the Princess. He is then dismissed with the dog to the city's docks, where he concludes his story.
The Princess is tricked into boarding Jaffar's ship. Jaffar tells her that she can cure Ahmad's blindness only by allowing the sorcerer to embrace her. She submits and the spells are lifted from both Ahmad and Abu. When the pair sail in pursuit, Jaffar raises a storm that shipwrecks them. Returning to Basra, Jaffar intrigues the Sultan with a life-sized automaton, 'The Silver Maiden', whom the Sultan embraces until she stabs him in the back. Jaffar then returns to Bagdad with the Princess.
Abu awakes alone on a deserted beach. He finds a bottle and opens it, releasing an enormous Djinn so embittered by his long imprisonment he announces he will kill the boy. Abu tricks the genie into submitting to him and granting him three wishes. The first wish is wasted, but the genie helps Abu steal a magical jewel, the All-Seeing Eye, that enables him to find and reunite with Ahmad. With the jewel, Ahmad sees Jaffar using his magic to make the Princess forget her true love. Despondent, Ahmad quarrels with Abu, who inadvertently uses his third wish to send Ahmad back to Bagdad.
In Bagdad, Ahmad is reunited with the Princess, who remembers him. They are imprisoned by Jaffar and condemned to death. Abu helplessly witnesses all this with the jewel's aid. In anger, he destroys the jewel, which frees the Old King of the Land of Legend. Abu is given a magic crossbow as a reward. He steals the king's magic carpet and flies on it to Bagdad. Abu's appearance fulfils an ancient prophecy and sparks a revolt against Jaffar by the city's inhabitants. Abu kills the fleeing Jaffar with the crossbow, and Ahmad is restored to power. Abu, alarmed by Ahmad's plans to educate him to become the vizier, flies off on the carpet in search of fun and adventure.