Hulagu Khan was a real person - he was the brother of Kublai Khan, the conqueror of Asia, and the Mongol leader who conquered Iran and Baghdad, as shown in the movie. But he appears to have died of natural causes, not by murder.
The movie does not follow the plot of the original story except in the scene where the forty thieves are stuffed in jars and then brought to the palace as a gift for the villain, Hulagu Khan.
The reason the plot of the fairy tale wasn't used for the movie may have had something to do with the fact that in the original fairy tale, there are some 42 murders; the first is Ali Baba's cousin, and the other forty-one are those of the forty thieves themselves and later, their ringleader who arrives at Ali Baba's disguised as a merchant and thirsting for revenge. He is the last of the Forty Thieves to die. The other forty thieves die when, after smuggling themselves into Ali Baba's house in wine casks, broiling hot water is poured into each of the casks containing a bandit.