
Ali Baba comes to know of this and kills them all with the help of Fatima.

Abu Hassan hides the 40 thieves in large urns to kill Ali Baba. What Ali Baba does not know is that the Khazi and Abu Hassan is the same person, and that the Khazi has given instructions to his men to ensure that Ali Baba is killed, so that no one can get their hands on his treasure.

Ali Baba then informs the Khazi about Abu Hassan's hideout. Out of greed Qasim takes so much gold jewelry and coin as a result of which he forgets the spell to reopen the door and gets stuck inside. Ali Baba-��s greedy brother Qasim lures Ali Baba into telling him where the cave is and those magic spells. He also gets some gold and jewelry from there, which he distributes amongst villagers for diverting some water to their parched land. Shortly, thereafter Ali Baba comes to know the secret hideout of Abu Hassan and its magic spells to open it. Fatima pledges her support to Ali Baba in killing Abu Hassan. A young girl named Fatima (Zeenat Aman) whose father has been murdered by the dacoits has a score to settle with Abu Hassan (Rolan Bykov). It is then the Khazi of the region announces a reward for the capture of notorious bandit Abu Hassan. Qasim wants to recover his money, and as a result decides to evict Ali Baba from their family home. After burying his father, Ali Baba finds out that Marjeena is being sold in the slave market, he borrows money from Qasim, and uses that to pay for Marjeena, and brings her home. Then they are attacked, Marjeena is taken captive, and his father is killed. Both Marjeena and Ali Baba fall in love with each other. When news reaches them that his father has gone missing, Ali Baba goes in his search and not only finds his father, but also rescues princess Marjeena (Hema Malini) from the guards of the king who murdered her father to become king. When the bandit leader recites the magical spell it opens and when he says another spell it closes.

They hide their loot in a magical cave in the deserted hills. Gulabad is terrorized by a band of 40 dacoits. So poor Ali Baba makes a living out of selling timber cut from the hills.

Ali Baba's father Yousuf is a merchant in a faraway land who has never returned since he last left when Ali Baba was born. The story is about a poor lad named Ali Baba (Dharmendra) who lives in the town of Gulabad, somewhere in central Asia, with his mother and elder brother Qasim who owns a small petty shop.
