Ali Baba demands from Qasim Al-Multazam, his cousin, to return his inheritance to him, but he refuses and agrees with his wife to frame Ali Baba with a charge so that he can get rid of him and put him in prison.
The treasurer's daughter claims that Ali Baba stole her jewelry, so he issues an arrest warrant. Morgana tries to uncover the truth. On the other hand, Sanqur agrees with the leader of the Forty Thieves gang to fill the cave with jewelry and gold.
The treasurer's daughter claims that Ali Baba was trying to kill her, so the latter escapes with Morgana from the town, and discovers the cave of The Forty Thieves. On the other hand, the market traders revolt because their money and goods are stolen by unknown people.
Al-Multazam and the treasurer file a complaint to the ruler of the state against Ali Baba, and the chief of merchants asks the treasurer to arrest the gang that is robbing market stores. The chief of merchants’ daughter stipulates that, for her marriage to the treasurer, he must arrest the gang.
Ali Baba finds gold and jewelry in the gang's cave and thinks about reporting the matter to the treasurer, but his friend prevents him for fear of being arrested and not being believed.
Ali Baba meets Yaquta, the chief of merchants' daughter, and warns her of the gang's plan to rob her father's palace, but when the chief of merchants tells the governor about it, the robbery does not take place.
Ali Baba believes that there is a traitor among the governor’s entourage, and that someone informed the gang about the police ambush at the chief of merchants' palace and he decides to expose him.
Ali Baba eavesdrops on the talk of the gang leader and Sanqur to take revenge on the chief of merchants, and the market merchants decide to file a complaint to the governor about the robberies taking place.
The gang tries to arrest the chief of merchants, but Ali Baba disguises himself as a masked knight and saves him. Ali Baba agrees with Bahloul to rob the cave and return the stolen money to its people.
The treasurer accuses the chief of merchants of cooperating with the gang to rob the market, while the gang leader tries to expose the traitor, who is leaking information about the gang and stealing gold from the cave.
The treasurer accuses the chief of merchants of attempting to assassinate the governor, so the latter issues a decision to arrest him. The treasurer bargains with Yaquta to marry her in exchange for the release of her father.
The chief of merchants refuses to marry his daughter to the treasurer. Ali Baba helps the chief of merchants escape from his prison and tells him about the cave and the gang.
The guards search for the chief of the merchants and Ali Baba reassures Yaquta that her father is safe. Ghada persuades her husband, Al-Multazam, to seek the help of the governor after his shop in the market burned down.
Ali Baba is thinking of devising a plan to release Bahloul from prison. The people revolt from the increase in taxes. Ali Baba and Morgana disguise themselves as two merchants from Morocco to enter the city and deposit the gold in the chief of merchants' palace.
The treasurer issues an order to confiscate the chief of merchants' caravan. Yaquta agrees with Ali Baba and Morgana to inform the governor about what is happening in the city. Ghada discovers Bahloul's involvement in helping the chief of merchants escape.
The gang leader catches Hankour and thinks he is the masked knight. Ghada asks Bahloul's wife to provide her with all the information about the chief of merchants' friends.
Yaquta tries to prove her father's innocence to the governor, and the latter orders the treasurer not to disturb Yaquta.
The treasurer returns the goods to the chief of merchants' stores to please Yaquta. The governor looks forward to marrying the latter. The treasurer arrests a passerby and believes him to be the Masked Knight.
Yaquta bargains with the governor to marry her in exchange for her father's return. Ali Baba disguises himself as an old man so that he is not caught by the treasurer's men. The governor balmes the latter for his failure to arrest the masked knight and the gang.
Morgana is worried that Ali Baba did not return home, but the latter meets Bahloul and asks him to deliver a message to Yaquta. Morgana goes out to search for Ali Baba and gets lost in the desert.
Ali Baba frees Hankour from captivity, and agrees with him to return the money and jewelry that Al-Multazam's had stolen. Ali Baba disguises himself as a merchant and hides Hankour in the gift box he gives to Al-Multazam’s wife.
Hankour comes out of the box in Al-Multazam's house, finds the jewelry and money, and Ali Baba returns them to their owners. Hankour agrees with Ali Baba to continue cooperating with him against the evil of the treasurer.
The treasurer revolts when he learns that Al-Multazam's jewelry has been stolen from his house. Market traders celebrate this, and Al-Multazam asks his wife Ghada to give him money to trade with after his huge loss.
Bahloul's wife informs the treasurer that the chief of merchants is hiding with Yaquta, so the treasurer arrests him and bargains with Yaquta to agree to marry him in exchange for leaving her father. The governor issues a ruling to return all the jewelry from the people to Al-Multazam.
The treasurer arrests the chief of merchants, and Ali Baba refuses to return the jewelry to Al-Multazam. Sanqur and the leader of the Forty Thieves gang threaten the Masked Knight.
Ali Baba promises Yaquta to free the chief of merchants from the hand of the treasurer. Ali Baba threatens Al-Multazam and ties him with ropes for what he did to the people. The governor tries to bargain with the chief of merchants to release him from prison in exchange for marrying his daughter.
The governor imprisons the chief of merchants. Ali Baba overhears the plan of the Forty Thieves gang to rob the palace of the chief of merchants and the governor, so Ali Baba goes and agrees with Hankour to warn them about the gang.
The governor issues a decision to arrest the gang members, so Sanqur suggests to the gang leader that they change their location. The treasurer becomes angry at the governor’s desire to marry Yaquta. Al-Multazam enters the cave and forgets the password to open the door, so he gets locked inside.
The gang catches Al-Multazam and locks him in the cave, and Ali Baba disguises himself as the masked knight and decides to free him.
The masked knight reveals to the treasurer the truth about his identity and that he is Ali Baba. A quarrel breaks out between Ali Baba and the gang leader. Everyone discovers that the latter is the treasurer. He is arrested, and Ali Baba marries Yaquta.