Ali Baba, fictional character, the hero of “Ali Baba and the Forty Thieves,” one of the best-known stories in The Thousand and One Nights. Ali Baba is a poor woodcutter who secretly watches as 40 thieves hide their booty in a cave, the door to which can be opened only by the verbal command of “Open, Sesame!” He later uses this magic phrase, steals riches from the cave, and lives a prosperous life. The thieves eventually suspect Ali Baba, and they hide themselves in large oil jars that, with the unsuspecting Ali’s permission, are stored overnight in Ali Baba’s courtyard.
When the slave Morgiana goes to extract oil from one of the jars, she hears a robber whisper. Morgiana realizes that the jars contain not oil but robbers lying in wait to kill her master. She pours hot oil into each jar, thus killing the robbers. Morgiana later saves Ali Baba’s life a second time, and in gratitude he frees her. She marries Ali Baba’s son, and the entire family lives prosperously on the wealth obtained from the cave that only they can enter.