In 1874, an idle young man, Pao Lung Sing (Stephen Chow), is appointed as county magistrate-in-waiting, a minor governmental official, after his father, a retired governmental official, purchased the position for him. Because the county magistrate Chan Pak Cheung had taken leave due to illness, Pao becomes acting magistrate, accompanied by his cowardly but loyal nephew, Pao Yau Wai (Ng Man-tat), as his advisor and personal assistant.
Pao is descendant to the famed Sung Dynasty judge Pao Ching, who is known for his impartiality. Pao, however, is corrupt and despised by the public for his money-digging ways, but is popular with the local gentry. He was invited by Master Chi, a rich merchant, to attend the wedding between his tuberculosis-ridden son and Chin Lin (Sharla Cheung Man), a beautiful young woman. During the wedding, however, Lei Pao (known by his nickname "Panther), the top kuai of the Pekingyamen, storms the occasion, claiming that the Chi family is harboring criminals on the run, who had disguised themselves as commoner guests at the wedding banquet. After subjugating the criminals, Lei threatens the Chi family for a bribe to be left alone, as he is also highly corrupt. Lei also robs the local citizenry of their material possessions using his masterful wushu techniques. Pao quickly shows allegiance to Lei, much to the disappointment to Master Chi, and offers to throw a banquet for Lei at the magistrate's court, promising many prostitutes. The offer pleases Lei, but when he arrived at the court, he is subdued by the guards. It turns out that Pao feigned allegiance to Lei and had planned on subduing him from causing further harm to innocent people. For this act, Pao is redeemed in the eyes of the county's folk.
Shang Wai (Collin Chou), the spoiled son of Navy Commander Shang Kwan (Ku Feng) and uncle-in-law to Chin Lin (now "Chi Siu Ling" by marriage), has an affair with his cousin and Siu Ling's mother-in-law, Yiu Yuen Kwan (Wong Fung-King). During the wedding banquet, Shang is smitten by the beauty of Siu Ling. Three months later, when on a visit to the Chi family, Shang secretly drugged Siu Ling and raped her when she was praying to the Buddha. Siu Ling awakens during the act, however, and after fiercely resisting, escapes. In a fit of uncontrollable rage, Shang murders all other members of the Chi family and burns their estate. Pao and the guards sees the fire when drinking out late, and apprehends Shang, detaining him in the county prison.
The wealth of the Shang family allows them to recruit the famed lawyer "Mirror" Fong Tong Kan, one of the Four Legendary Advocates of Canton, equally famous for his skill and his lack of scruples. Buttering up to Pao, Fong requests for permission for Shang's grandmother to visit him in jail, which Pao grants. Fong brings Kwan instead, and cooks up a plan to frame Siu Ling for the murders instead. Kwan's men removed evidence of Shang's involvement and planted evidence that indicted Siu Ling. To prevent Pao from interfering, Fong offers Pao a generous bribe, knowing that he could not resist such an amount. The next day, Fong successfully sued Pao for corruption, a charge that he could not deny and was thus taken into custody. He subsequently convinced the acting judge that Siu Ling committed the crime, who ordered Siu Ling to be placed on death row, putting her in jail after caning her half to death.
Utilizing connections from Pao's father, Yau Wai manages to break Pao out of jail. Pao promises Siu Ling to bring Shang to justice and save her. On his deathbed, Pao's father asks Pao to seek help from Lord Fa, the Minister of Justice and his old friend, in Peking. During their journey, they encounter all sorts of wacky characters, including Stone Mansion a circus performer and Yu Yin a classy prostitute. In the end, the real perpetrator of the mass murder is cut in half with a guillotine and the corrupt officials are brought to justice including lawyer Fong.