At the end of the film Aladdin, the title character tricked Jafar into wishing he was an all-powerful genie. Aladdin, knowing the evil sorcerer would be sealed into a lamp for eternity to do a master's bidding, held up Jafar's black, would-be prison that appears once the wish is granted by Genie and it swallowed Jafar (while pulling Iago with him) inside where they start fighting. Genie then sent the lamp far into the Cave of Wonders for 10,000 years.
In The Return of Jafar, Iago managed to escape the lamp, but instead of releasing Jafar from it, he threw it down a nearby well, due to Iago having grown irritated that Jafar does not grant him credit when it is due, and instead used him (with Jafar also making the grave mistake of reminding Iago shouting "Polly Want a Cracker" that finalized Iago's decision).
Later, Abis Mal finds the lamp at the well and rubbed it, releasing Jafar. At the end of the film, Aladdin and his friends tried to capture Jafar's lamp so they could destroy it, which would thus destroy Jafar. In the end, a wounded Iago, having fully turned against Jafar, kicked the lamp into a lava pit and it melted away, causing Jafar to electrocute, then implode into nothingness, destroying him forever.
Jafar was pulled into a lamp once again by Mickey Mouse at the end of Mickey's House of Villains. However, this lamp looked like the one that belonged to Genie. This actually makes sense, as the original black lamp had been destroyed in The Return of Jafar.