Ali Baba was a poor woodcutter who lived in the forest with his wife and children. His brother, Cassim, married a wealthy woman and lived in the city. One day while Ali Baba was working in the forest, a group of 40 men approached the area. Ali Baba climbed into a tree to escape detection, fearing correctly that they were thieves.
Ali Baba watched the thieves, who stopped in front of a cave. The captain of the thieves called "Open Sesame!" and the thieves disappeared into the cave. When they returned the captain called "Close Sesame!" and the cave closed behind them. Curious, Ali Baba climbed down from the tree after they left and discovered their treasure store hidden in the cave, only seen by calling the magic words. He took some of the gold and his wife borrowed Cassim's scale to weigh it. Cassim learned of the treasure and demanded to see it. Upon entering the cave he forgot the words to exit and was found and killed by the thieves. Ali Baba found his brother's body and returned it to Cassim's wife for burial. The thieves sought out Ali Baba for stealing their gold. Thirty-nine of the thieves hid in oil barrels while the captain posed as a oil merchant seeking shelter from Ali Baba for the night. The slave girl Morgiana discovered the thieves hiding and poured boiling oil on them, killing them. The captain escaped but returned later under a different disguise. Morgiana recognized him and bravely stabbed the captain before he could kill Ali Baba or his family. As a reward, Ali Baba married Morgiana to his son and they all lived happily with the thieves' treasure.