In a town in Persia lived two brothers – Cassim and Ali Baba. Cassim was rich, but Ali Baba was poor, and gained his living by cutting wood, and bringing it upon three asses into the town to sell. One day he saw some robbers in a forest ; he watched them from a hiding-place, and counted forty of them ; they carried bags of treasure, and hid it in a cave, which opened for them in the solid rock on saying the words « Open Sesame ». When they came out again, the captain said « Shut Sesame » and the door shut behind them, and they rode off. The Ali Baba came down from his hiding- place, and went to the rock and said « Open Sesame » and a door opened and he entered and found all manner of treasure ; he carried off a quantity of gold coin, and lading his asses with it, went home. When he showed it to his wife, she wanted to measure it, to see how much they possessed, and she went to Cassim's wife to borrow a measure, and Cassim's wife lent it to her, patting some suet at the bottom of the measure.
Alli Baba and his wife then measured the gold, and buried it in the ground ; and when Cassim's wife received back the measure, she found a piece of gold sticking to the suet. She told Cassim, who persuaded his brother to tell him the secret of the cave, and went next day to get treasure for himself. He entered the cave by saying « Open Sesame » ; but when he was ready to depart, having gathered many bags together, he could not think of the magic words, and so obliged to remain in the cave till the robbers returned who, enraged at having their secret discovered, killed him, and cut his body into four quarters, hanging them inside the cave.
Cassim's wife, finding that her husband did not return, went to tell Ali Baba, who at once set off to go to the cave, and on entering it discovered his brother's remains, which he carried home on one of his asses, loading the other two with bags of gold. Ali Baba then buried the body and contrived, with the assistance of an intelligent slave named Morgiana, to make everyone believe that Cassim had died a natural death. Ali Baba then married the widow, and became rich and prosperous.
Meanwhile the forty robbers visited their cave, and finding that Cassim's body had been removed, determined not to rest until they had discovered their enemy ; and one of them undertaking the search, in which he was assisted by the Cobbler who had sewn Cassim's body together, at last found Ali Baba's house, which he marked with a piece of chalk, and returned to his fellows. When Morgiana saw the mark, she chalked several other doors in the same manner. The thieves then coming to attack the house, and not being able to distinguish it from the others, had to return to their cave ; and the robber, who they thought had misled them, was put to death. Another robber then undertook the enterprise, and, being guided by the Cobbler, marked the door with red chalk, but Morgiana marked the neighbour's doors in the same manner, and so defeated them a second time ; and the second robber was put to death.
The Captain then went into the town himself, and having found and carefully observed Ai Baba's house, returned to his men, and ordered them to buy nineteen mules and thirty-eight leathern jars, one full of oil and the rest empty. This they did, and the Captain placing one of his men in each of the empty jars, loaded the asses, and drove them into the town to Ali Baba's house. Ali Baba received him hospitably ; and the Captain ordered his men, who remained in their jars in the yard, to come out in the middle of the night at a signal from him.
He then went to bed ; and Morgiana happening to need oil, went to help herself out of the jars of the guest ; she found, instead of oil, a man in every jar but one. Determined that they should not escape, and heating a quantity of oil, she poured some into each jar, killing the robber within. So when the captain gave the signal to his men, none of them appeared, and going to the jars he found them all dead ; so he went his way full of rage and despair, and returned to the cave, and then formed a project of revenge. Next day he went into the town, and hiring a warehouse, which he furnished with rich goods, became acquainted with Ali Baba's son, who one day invited him to his father's house. On hearing that the new guest would eat no salt with his meat, Morgiana's suspicions were aroused, and she recognised him as the captain of the robbers. After dinner she undertook to perform a dance before the company, and at the end of it pointed a dagger at the captain, and then plunged it into his heart.
Ali Baba was very much shocked, until Morgiana explained the reasons for her conduct ; he then gave her to his son in marriage, and they lived in great prosperity and happiness ever after.