Shahrazad tells King Shahryar the story of Ali Baba and the forty thieves, the leader of whom is Shoman. As Ali Baba sells earrings, his brother Cassim plans to be a Shahbandar.
The vizier, Ateek, summons the Jinn Dumdum, who refuses to help him until after Sultan Alish dies. Ali tells his wife, Rumana, that the witch Ghawashim is the reason why his father kicked him out of the house.
Hawanem gives birth to a girl, and Rumana gives birth to a boy and dies during childbirth. When Cassim becomes Shahbandar of the merchants, he sends the maid to replace his daughter with Ali's son, as Ghawashim requested.
When the guards catch Haddaya, Haddaya's mother tells Ali what Cassim did, and she takes the girl to raise her. Ali runs away and discovers the forty thieves' secret and enters the cave.
When the forty thieves come back and find what is in the cave is stolen, Shoman and the gang suspect Haddaya, whom they search for, but do not find him. Later, they accuse Semsem of betraying them, so he leaves them and leaves the entrance of the cave open.
Semsem goes to the Nahas City. King El Maskouk, the King of the Jinns, exiles his son, Mahbouk with the Harafish, for refusing to marry the daughter of King Fintas. Cassim becomes the treasurer of the House of Money.
The owner of the palace at the edge of the forest invites the minister, Cassim, and all the people of the country to his palace. When everyone goes to the palace, they discover that Ali is the owner and the two children, Ghanem and Yasmina, have grown up.
Cassim's condition worsens after Ali's return and Ghawashim's illness, and Ateek releases Haddaya from prison at the request of Ali. When Shar El Tariq (the evil of the road) informs Cassim of Haddayah's release, Hawanem asks him to kill Ali.
Haddaya meets his mother and Ali. As Cassim and Hawanem learn of Ali stealing the cave from Ghawashim, Ali tells Haddaya about him robbing the cave. Cassim goes to the cave to inform the gang that Ali stole from them.
When Cassim informs the gang that Ali robbed them in agreement with Haddaya, the latter hears what Cassim said to Shoman. Shoman detains Cassim until he confirms what he said. Elsewhere, Ali Baba meets Alish and confesses to him about everything.
Hawanem goes to Ali's palace, and Shoman releases Cassim. Later on, Cassim agrees with Ateek and Shar El Tariq to get rid of Ali.
Shoman impersonates Shahbandar of the merchants of the Levant, and goes to Ali's palace. Alish goes to Ali's palace, and rules the return of the money that Ali had stolen from the gang to the House of Money, and Shoman is appointed chief of police.
As Alish appoints Ali Baba as the Minister of the Country, Cassim and Ezra are dismissed from their positions. The members of the Forty Gang become the police, and Alish informs Ali that after his death, the Jinns will take over the country.
Cassim and Hawanem visit Ali and he promises them that Cassim will work with him. Alish cancels the taxes, and Ali Baba provides work for all the unemployed. Ghawashim summons Dumdum, and she dies. Ateek and Cassim tell Dumdum what Alish did, and Mahbouk returns to the kingdom of Maskouk.
When Dumdum informs Maskouk what Alish did, Maskouk commands that Mahbouk rule the humans. Dumdum asks Hawanem to start helping him and promises her to make her a sultana. Elsewhere, Mahbouk and Semsem go to the cave.
Hawanem and Cassim ask Ali to marry Yasmina to Ghanem and to persuade Alish to visit them in their palace. Hawanem begins working with Dumdum, and Ali Baba persuades Alish to go to Cassim's palace. Dumdum discovers that Mahbouk is plotting to spoil Maskouk's plans.
Maskouk imprisons Mahbouk in Nahas City, and Semsem informs Shoman and Haddaya what is being arranged for Ali and Alish. On the other hand, Balaha tells Cassim and Hawanem about seeing Semsem with Haddaya and Shoman. Later on, Ali goes to Cassim's palace.
When Alish arrives at Cassim's palace, Hawanem gets rid of everyone with poisoned incense. Shoman, Haddaya, his mother, and Yasmina escape.
Hawanem spreads throughout the country the rumor of Alish and Ali's murder by the Forty Gang. Elsewhere, Ali and Alish wake up in Ghawashim's room. Dumdum takes Ali and Alish to meet Maskouk, who exiled them to the Nahas Island, where they meet Mahbouk.
As Hawanem takes over the Sultanate, she asks to see Maskouk. Shoman and Haddaya decide to leave the country and take Yasmina with them, training her to fight.
Shoman trains Yasmina, and the years pass and she becomes a knight. Shoman, Haddaya, and Yasmina return to the cave, and Semsem goes out to learn the country's news.
As ten years have passed since the rule of Hawanem, everyone wears yellow tarots, and laughter and singing are forbidden in the country for fear of the jinn Maskouk. The dervishes take over the governing council, and Haddayah goes to see his mother.
When Haddaya, Shoman, and Yasmina see Ali Baba in the crystal ball, they know that he is still alive. After Alish tells Ali and Mahbouk the secret that will eliminate Maskouk, he dies.
Semsem tells Ali that Yasmina is with Haddaya. The thieves rob the Takyeh and leave a message in the name of Ali Baba. Haddaya takes his mother to stay with him in the cave. Hawanem learns of the theft of the Takyeh and of Ali Baba's message.
Ali refuses to reveal Alish's secret to Dumdum. When Cassim goes to the cave with the guards to make sure of Ali Baba's return, Semsem does not open for him. Hawanem asks Ghanem to go to the cave.
Maskouk agrees to Ali Baba's return to his country and to take revenge on Hawanem and Cassim, in exchange for Mahbouk telling him about Alish's secret. As Ghanem enters the cave alone, he sees Yasmina.
After Ghanem learns the truth about his parents, he returns to his palace. Ali enters the cave and meets Yasmina. Dumdum informs Hawanem of Ali and Maskouk's agreement. Later on, Cassim tells Hawanim that Ghanem discovered the truth about her getting rid of Ali and Alish.
When Shar El Tariq attacks the cave, Ali Baba and Yasmina leave it, and they all go to Haddayah’s mother’s cabin. Cassim tells Hawanem of his desire to inform Ghanem of the fact that Ali is his father. Meanwhile, Ali agrees to work together with Zarbal.
When Hawanem learns of Ali's appearance in the market and his escape from Shar El Tariq, she agrees with Hataba to spy on Ali. So, Hataba goes to inform Ali of the agreement.
Ali impersonates Cassim and enters the palace with his companions and takes over the palace. Meanwhile, Hawanem orders Cassim to be imprisoned before revealing her secret to Ghanem. Dumdum asks Semsem to help him and break the bottle.
Hawanem orders the imprisonment, hanging, and burning of the homes of all those connected to Ali. Meanwhile, Hataba informs Ali that he should meet with Zarbal because Hawanem assigned a mission to him.
The statues return to humans again in Copper City. As Ali comes out to the people as Cassim and they begin to chant against Maskouk and Hawanem, Maskouk is destroyed and Hawanem kills herself. As Yasmina and Ghanem learn the truth about their parents, the two brothers reconcile and Ali takes over the Sultanate.