The Mad Monk

The Mad Monk (Chinese: 濟公; pinyin: Jì Gōng is a 1993 Hong Kong fantasy comedy film directed by Johnnie To, and starring Stephen Chow as the "Mad Monk" Ji Gong, a popular Chinese folklore figure from the Southern Song dynasty. The film follows "Dragon Fighter Luohan" as he accepts a challenge from the gods to change the fate of a beggar, a prostitute, and a villain in three heavenly days. He is reborn on earth as a mere mortal and ultimately battles an evil demon to stave off hell on earth.
The gods in Heaven complain to the Jade Emperor about the malicious practical jokes played on them by Dragon Fighter Lohan. The Emperor summons Dragon, but Tiger Fighter Lohan appears instead to defend his friend. Dragon then appears and rebukes the various gods for their own horrible judgments on mankind, and insists that he can do a better job. When the Jade Emperor banishes Dragon and Tiger to be reincarnated as animals, the Bodhisattva Guan Yin intervenes. Jade Emperor issues Dragon a challenge: if he can change the fates of three people destined to nine incarnations in the same roles — a beggar, a prostitute, and a villain — he will not be punished. The Bodhisattva gives Dragon a magical fan to help him in his mission - but Tiger takes the fan away from him moments before he is forced down from heaven.
Dragon is reborn to a couple who visit a Buddhist temple to pray for a child. Tiger enlists the aid of a heavenly soldier named Unicorn to help him take the magical fan to Dragon. When Tiger is reincarnated he is much younger than Dragon. Unicorn uses his magic to make Tiger rapidly age physically, but Tiger's mental abilities remains that of a baby. Dragon's parents adopt Tiger and treat him as their own son.
Dragon regains his memories when he is struck by lightning during an encounter with Bai Xiao Yu, the prostitute. In short order, he also encounters the beggar Ta Chung and the villain Yuan Ba Tian. When the clouds block the moon and heavenly security is the most relaxed, Tiger regains himself enough to give Dragon the magic fan before being forced to return to Heaven.
Dragon tries to instil dignity to Ta Chung, persuade Xiao Yu to change her trade, and Yuan to turn over a new leaf. After he notices Ta Chung retaining some dignity while in front of Xiao Yu, Dragon arranges a date for the both of them. Yuan attacks Dragon during the date, and goes on to murder Ta Chung. Yuan then forces Dragon to watch while he assaults Xiao Yu. Before Ta Chung dies, he regains his dignity by seeing himself by his own name and not as a beggar.
Dragon retrieves a holy relic, the Golden Skeleton, his body from a former life. He travels to the underworld where he confronts a demon and trades the skeleton for Ta Chung's soul. The demon keeps both the soul and the holy relic and sends Dragon back to the land of the living. Dragon rushes to the temple and learns all of the local gods housed there are leaving; because of Dragon's deal with the demon, they do not want to be associated with him. Dragon seeks out Xiao Yu and promises to marry her if she gives up the sex trade. She agrees, but when Dragon begins to transform into a tree because of a prohibition against gods marrying mortals, she thinks he is playing a joke on her.
Yuan slaughters all the people in the brothel so he can use their blood to rid Dragon's relic of its power. Dragon goes to the brothel to confront Yuan and is able to regain his proper form. Dragon attacks Yuan and discovers that Yuan has been given an invincible body by the demon. Dragon pulls Yuan's heart out to show him that the demon gave him a stone heart. A dying Yuan regrets all the bad things he has done, asks to be reborn as an animal in his next life, and crushes the stone heart.
Dragon is given a chance to return to Heaven, but stays to prevent the demon from bringing destruction to those on Earth. He imbues his power into his holy relic and makes it into golden paint, using it to write protective talismans around the temple. The demon blows away the talismans and chases Dragon. Fleeing from the demon, Dragon meets the temple Abbot and asks for his help: the Abbot makes the demon laugh and Dragon jumps into the demon's mouth, causing him to explode and die.
The gods celebrate as Dragon has seemingly lost the bet. Guan Yin interrupts the festivities and shows how Dragon has succeeded in changing the fates of the three people: Ta Chung has regained his dignity and was born again into a wealthy loving family, Xiao Yu has left prostitution behind and opened a bean curd restaurant, and Yuan renounced violence and thus was reborn as a pig. Dragon is in the end victorious, receiving a tiara and a scepter given to him in a mock pageant where all the gods cheer him.