During the Changqing era of Emperor Muzong of Tang, the scholar Pei Hang fails the imperial examinations and travels to Ezhou. Along the way, he encounters the sudden illness of Chancellor Cui’s mother and saves her with a secret remedy passed down through his family. Chancellor Cui offers him 200,000 coins in thanks, so Pei Hang hires a boat to carry the money back to Chang’an. Having fallen for Lady Fan, who is traveling on the same boat, he asks her maid Niao Yan to deliver a poem declaring his love, and sends her fine wine and rare fruit as gifts. Lady Fan has Niao Yan return a poem, then departs without a word. With no other choice, Pei Hang gathers his things and continues toward Chang’an.
At Lanqiao Station, parched with thirst, he asks an old woman for a drink. She sends her granddaughter to bring him water. He is astonished to hear that the girl shares the name Yunying, mentioned in Lady Fan’s poem. He stays there, hoping for a chance to ask for her hand. The old woman claims Yunying is ill and says that Pei Hang must obtain a jade pestle and mortar and grind medicine for a hundred days before they can discuss marriage. Back in the capital, Pei Hang tries every possible means to acquire the jade pestle and mortar for 200 strings of cash. He brings them to Lanqiao and spends a hundred days grinding the medicine. After the old woman takes it, she brings Yunying back to her grotto. Before long, she also invites Pei Hang there to meet the many immortals and their beautiful companions. Among them, a fairy introduces herself as Yunying’s older sister. Pei Hang takes one look and realizes she is Lady Fan, his fellow passenger from Ezhou, who has attained the Way and become a celestial official in the Jade Emperor’s service. He is even more astonished.
After marrying Yunying, Pei Hang settles with her in Jade Peak Cave and transcends the mortal world to become an immortal himself. Later, turmoil breaks out in the Tang Dynasty, leaving the people in dire poverty. With the help of his wife Yunying and Lady Fan, Pei Hang puts down the rebellion and eliminates corrupt officials at court, allowing the people to live in peace and happiness. The emperor bestows on him the title of Worthy Prince of the Nine Thousand Years, but Pei Hang has no desire for honors or rewards. He returns with Yunying to Jade Peak Cave, where they enjoy the life of immortals.