Marziana (P. Bhanumathi) is a dancer in Baghdad. The tyrant Sher Khan, commander of the notorious king Amir Kasim Khan (M. G. Chakrapani), tries to take her by force to his palace. She is rescued by Ali Baba (M. G. Ramachandran), who fights with Sher Khan and vanquishes him. Marziana and her sidekick Dowlat (K. Sarangkapani) find refuge in Ali Baba’s house. Alibaba is an impoverished woodcutter and lives with his sister Ayisha (P. Susheela) and servant Bulbul (M. N. Rajam). Marziana learns that they are the siblings of Kasim, who had driven them out at the instigation of his cruel wife Salima (Vidyavati). Marziana and Ali Baba later fall in love.
One day, when Ali Baba goes to cut wood, he chances upon the cavernous hideout of Abu Hussain (P. S. Veerappa), the notorious leader of forty dacoits, and overhears the secret code to enter and exit the cave. After the dacoits leave, Ali Baba uses the code word, enters the hideout and takes some of the cave's wealth which he uses to help the poor people around. Both Ali Baba and Marziana become wealthy overnight.
Kasim becomes jealous when he hears about his brother's fortune, and wants to know how Ali Baba became rich overnight. Under Salima’s guidance, he invites Ali Baba and his household for a feast. Cunningly obtaining the secret of the dacoit's cave from Ali Baba, he then orders Ali Baba’s arrest, accusing him falsely of attempted murder. Marziana pretends to hail Kasim’s order. She declares that Ali Baba had been unfaithful to her and he deserved this retribution. Taking a knife, Marziana acts as though she means to kill Ali Baba, but instead cuts the ropes that bind his hands. Ali Baba is freed and after defeating Kasim's thugs, escapes with Marziana.
Kasim enters the cave and greedily starts collecting many treasures. He soon forgets the code word, and is left trapped. The dacoits arrive, and kill him for entering their secret cave. Ali Baba visits the cave and is shocked to see his brother dead; he later takes away the corpse. After Kasim's death is publicly announced, Ali Baba is declared the new king of Baghdad and everyone rejoices. Meanwhile, the dacoits return to their cave and see that Kasim's body is missing. Realising that someone else has entered their cave, they start searching for the mystery person.
From the cobbler Gulam’s (K. A. Thangavelu) assertion that the woodcutter Ali Baba had become wealthy overnight, Abu Hussain realises that it is Ali Baba who discovered the secret of his cave. However, he kills the cobbler afterwards. Having his men hidden inside barrels, Abu Hussain comes to Ali Baba’s house disguised as an oil merchant seeking shelter for the night. However, Marziana overhears him whispering to his men hidden in the barrels, and realises his true identity. When she dances at a banquet that Ali Baba hosts in honour of the guest, Dowlat and Bulbul roll the barrels one by one into the swirling waters as per the plan. After Marziana unsuccessfully tries to stab the "oil merchant", she exposes him as Abu Hussain and Ali Baba is shocked. This leads to a fight between the two men, which results in Abu Hussain kidnapping Marziana and fleeing to the secret cave. Ali Baba chases him and reaches the cave, where he kills Abu Hussain after an intense battle. After Ali Baba rescues Marziana, they both get married and continue to serve the poor people.