It's Founder's Day in Agrabah, the day the Sultan's ancestor, Hamed, found the city. While everyone is enjoying the holiday, Abis Mal steals a magic hourglass holding the Sands of Time from the mystic. Aladdin and his friends stop Abis Mal, but the thug creates a green hourglass-shaped portal and goes in there and Agrabah changes: the buildings are suddenly dilapidated, the Hamed banners are now Abis Mal banners, and the palace changes.
Aladdin and the others get in the portal and find themselves in a desert, the time before Agrabah existed. The gang runs into Hamed and suggests that he and the caravan stay where they are because this is where he created Agrabah. Then, a man who looks just like Abis Mal (except he doesn't have a goatee) comes out of a cart and Aladdin tackles him. Then the street rat realizes that the man is Abnor Mal, Abis Mal's ancestor. Aladdin and his friends tell Hamed that the desert is the perfect place for them to settle in and he agrees. Abnor gets angry because he wanted to make tents, then he runs into Abis Mal, who talks him into becoming Sultan of Agrabah. Abnor agrees and then he let's Abis know about Aladdin following him, which makes the thug worry.
It's nighttime and Aladdin, Jasmine, and Hamed are sitting around a campfire. After Hamed talks to them about his plan on building Agrabah, they go to sleep in tents, and Abis and Abnor Mal tackle Hamed. Aladdin and the others see this and go after the Mals. When they go to them, Abis creates the hourglass-shaped portal and throws Hamed in there and then Jasmine vanishes. Abis Mal tells them that he changed history: No Hamed meaning no Jasmine. Aladdin and Genie go in the portal and it closes. Abis Mal sees Iago and Abu and makes the animals slaves.
Aladdin and Genie are in a distant past and the two see Hamed sinking into a tar pit. While Genie tries to keep the portal open, Aladdin uses a vine to rescue Hamed, but then he runs into a saber-toothed tiger. The street rat puts the vines around the tiger and makes it chase him until it falls off a cliff and Hamed is out of the pit. Aladdin, Genie, and Hamed get in the portal and get back in the desert. Jasmine is back and Aladdin's happy to see her.
Hamed thinks the desert is cursed and he wants to leave, but Genie shows him that his group, Abu, and Iago are working for Abis and Abnor Mal. The four get an idea. Genie makes the Mals fill out forms. Abis sees that Aladdin is back and is about to doom him with his hourglass, but Abnor takes it away from him because he wants to end Aladdin's life. The Mals then fight over the hourglass and Aladdin snatches it away from them. Abis and Abnor tackle the street rat and the hourglass breaks, making it create a giant time portal in the sky that sucks everything in it. Aladdin, the Mals, and Hamed get sucked in the portal and end up in-between different time periods.
Later, a portal opens and Hamed sees Agrabah and begins to understand Aladdin's suggestion. In the desert, Genie sucks the portal into his mouth and spits it and everyone out into a mug. After Hamed thanks Aladdin, Genie opens the portal that takes them back to their time. Hamed and his group are now about to create Agrabah while Abnor Mal decides to live in the desert as an outcast.
Back in Aladdin's time, everything is back to normal. Aladdin asks Genie where Abis Mal is, but the jinn tells the street rat not to worry about him. Abis Mal is at the prehistoric landscape getting chased by the saber-toothed tiger from earlier.