A clan of bandits, led by the incompetent Abis Mal, return to their hideout, only to have the brunt of their loot taken by Aladdin and Abu. Aladdin distributes the treasure amongst the poor of Agrabah - with the exception of a jewel flower, which Aladdin gives to Jasmine.
Meanwhile, in the desert, Iago manages to dig himself and Jafar's genie lamp out of the sand, where they were exiled by the Genie. Jafar orders Iago to release him, but Iago rebels against Jafar and throws the lamp into a nearby well. He returns to Agrabah, hoping to gain favor with Aladdin, in order to return to the palace. When he encounters Aladdin, his claim of being a slave under hypnosis does not fare well and is pursued. Aladdin runs into Abis Mal and his bandits, but is inadvertently rescued by Iago. Aladdin returns to the palace and jails Iago, promising to allow a fair trial. He and Jasmine are greeted by the Genie, who has returned from seeing the world and is content with staying with his friends.
At a special dinner held in Aladdin's honor, the Sultan announces that he wants to make Aladdin his new grand vizier. Trying to draw on the good mood, Aladdin attempts to persuade the Sultan to forgive Iago, but Iago inadvertently ruins the dinner when Rajah chases him into the room. The Sultan and Jasmine are furious, and Jasmine leaves the room heartbroken that Aladdin did not trust even her about this. With Iago's help, though, Jasmine eventually reconciles with Aladdin.
While Abis Mal is washing himself at a well, he finds Jafar's lamp and when it is rubbed, Jafar appears as an abominable genie. Although bound by the laws of obedience, Jafar manipulates his master into wasting his first two wishes, but forms an alliance to the end of exacting revenge upon Aladdin. The pair travel to Agrabah, where Jafar reveals himself to Iago and coerces him into complying with his schemes. The next day, Aladdin and the Sultan depart to have a discussion about Iago's fate, while Jafar confronts the Genie and Abu in the Palace gardens and imprisons them.
When Aladdin makes good progress with his discussions with the sultan, he is ambushed by Abis Mal, who is supported by Jafar's sorcery. The Sultan is kidnapped and Aladdin thrown into the raging river. Jafar frames Aladdin for the alleged murder of the sultan by leaving fake evidence and disguises himself as Jasmine to implicate Aladdin. Thus, Aladdin is thrown into the dungeon, to be executed by beheading come morning.
In the dungeon, Iago chooses to side with Aladdin's friends by releasing the Genie, to save Aladdin. Once everyone is freed, Aladdin decides to destroy Jafar, which could only occur once his lamp would be destroyed. Jafar and Abis Mal celebrate Aladdin's death, but Jafar demands to be set him free. Abis Mal hesitates, however, being suspicious of Jafar's motives. Aladdin attempts to steal the lamp, but is discovered and is blown them out of the throne room and into the palace garden. Aladdin, Jasmine, the Genie, Abu and Carpet engage Jafar in combat, but even when bound by the rules of the Genie, he easily outmatches them, using his tremendous powers to stop them from obtaining the lamp. His indiscriminate use of power opens a fissure in the ground which is filled with magma. Thoroughly trapped, Aladdin, Jasmine, the Genie, and Abu face certain death when suddenly Iago reappears and grabs the lamp. Jafar blasts him, leaving him for dead, but Iago manages to recover for a moment and uses his last ounce of strength to push the lamp into the magma. The lamp is destroyed, thus Jafar is destroyed.
Iago recovers from his injuries, since a genie cannot kill. Aladdin announces to the Sultan that he is not yet ready to become a grand vizier, because he first wants to see the world. Jasmine declares that she will join him, but Iago objects to this and continues to rant as the film ends.