The Genie is one of the main characters from Aladdin. He was also the film's tritagonist. He was portrayed by Robin Williams in the first film. After a contract dispute between Williams and the Walt Disney Company, Dan Castellaneta voiced the Genie throughout the direct-to-video feature The Return of Jafar, as well as the television series, before Williams reprised the role for the final installment, Aladdin and the King of Thieves, as well for the character's own mini-series, Great Minds Think for Themselves. Castellaneta voiced the Genie in the Kingdom Hearts series of video games by Square Enix and Disney Interactive Studios. In 2008, Williams reprised his role yet again in Disney Think Fast video game.
As well as largely driving the plot in the first movie, the Genie serves as comic relief in each of his appearances. He is shown to have unlimited shapeshifting abilities, which allow for many and varied sight gags. The Genie's supernatural abilities permit him to break the fourth wall, as well as parody real-life people and popular culture completely outside of the boundaries of the fictional universe in which he is contained. Not only can he make extra-canonical references, but the other characters even know what he is talking about (for example, when he turned his head into Pinocchio's head, complete with his signature elongated nose, to imply that he thought Aladdin was lying about his promise to free the Genie, Aladdin know enough about the story of Pinnochio to push his nose back in). From his appearances in the Aladdin franchise, it seems that Genie can turn himself, and also other people and animals, into anything he pleases. Williams is responsible for most of these because he improvised many of the lines in the film. However, even though Robin Williams is credited with most of this, it is still a trait shared by all genies in the Aladdin universe, including Jafar, after being turned into a genie (as demonstrated in his song "You're Only Second Rate"), as well as a female genie from the TV series that Genie falls in love with.The Genie first appears in Aladdin, where he is released from a magical oil lamp by the titular character in the collapsed Cave of Wonders. After he reveals that he can grant three wishes, Aladdin knowing that Genie would only grant his wish to get out of the cave, if he used one of his wishes, dupes him into freeing Aladdin and Abu from the cave without using a wish. At a faraway oasis, the Genie is shocked when he finds that Aladdin didn't use his first wish to get out of the cave and reluctantly agrees to let Aladdin's first wish to be spared. Asked by Aladdin what he would wish for, the Genie admits he would wish for freedom, since he is a prisoner to his lamp and must follow the orders of the lamp's master (Aladdin). After accepting a promise from Aladdin that Aladdin would use the third wish to set the Genie free, the Genie grants Aladdin his first wish: making him a prince so he can marry Jasmine. The Genie goes into hiding after leading a parade to the Agrabah palace. The Genie is released again when Aladdin is shackled, gagged, and thrown off a cliff into the ocean by Jafar's guards. The Genie rescues Aladdin as the second wish after liberally interpreting Aladdin's nodding head. Later, Genie has a falling out with Aladdin when he starts to think he may have to break his promise to use the third wish, out of fear of what will happen should someone find out he isn't royalty.
The Genie's lamp is later stolen and delivered to Jafar by Iago, making Jafar Genie's new master. The Genie has no choice but to grant Jafar's first and second wish to become Sultan of Agrabah and the world's most powerful sorcerer. He is then made a slave with no purpose in life but to entertain the sadistic Jafar by tormenting the former Sultan. During the final fight between Aladdin and Jafar, the Genie is forced to grant Jafar's final wish to become an all-powerful Genie when Aladdin convinces him to do so. However, as they both know, the fulfillment of this wish causes Jafar to be imprisoned in a lamp of his own, which the Genie hurls into the desert, freeing Agrabah from his tyranny. While the Genie is now more than willing to sacrifice his freedom in order to allow Aladdin to be with Jasmine, Aladdin decides to live up to his original promise and uses his final wish to free Genie from his lamp's power, much to the latter's surprise and happiness. Aladdin still gets to marry Jasmine, as the Sultan is touched by the young couple's love for one another, so he changes the law so the princess can marry whomever she pleases. The now-free Genie leaves Agrabah to explore the world.