However, word of Yingying's beauty soon reaches Sun the Flying Tiger, a local bandit. He dispatches ruffians to surround the monastery, in the hopes of taking her as his consort. Yingying's mother agrees that whoever drives the bandits away can have Yingying's hand in marriage, so Zhang Sheng contacts his childhood friend General Du, who is stationed not far away. The general subdues the bandits, and it seems that Zhang Sheng and Cui Yingying are set to be married. However, Yingying's mother begins to regret her rash promise to Zhang Sheng, and takes back her word, with the excuse that Yingying is already betrothed to the son of another high official of the court. The two young lovers are greatly disappointed, and begin to pine away with their unfulfilled love. Fortunately, Yingying's maid, Hong Niang, takes pity on them, and ingeniously arranges to bring them together in a secret union. When Yingying's mother discovers what her daughter has done, she reluctantly consents to a formal marriage on one condition: Zhang must travel to the capital and pass the civil service examination. To the joy of the young lovers, Zhang Sheng proves to be a brilliant scholar, and is appointed to high office. The story thus ends on a happy note, as the two are finally married.
The story of Romance of the West Chamber was first told in a literary Chinese short story written by Yuan Zhen during the Tang Dynasty. This version was called The Story of Yingying, or Yingying's Biography. This version differs from the later play in that Zhang Sheng ultimately breaks from Yingying, and does not ask for her hand in marriage. Despite the unhappy ending, the story was popular with later writers, and recitative works based on it began accumulating in the centuries that followed. Perhaps bowing to popular sentiment, the ending gradually changed to the happy one seen in the play. The first example of the modified version is an oral performance by a Deng Jieyuan of the Qing Dynasty. Wang Shifu's play was closely modeled on this performance.
Due to scenes that unambiguously described Zhang Sheng and Cui Yingying fulfilling their love outside of the bond of marriage, moralists have traditionally considered Romance of the West Chamber to be an indecent, immoral, and licentious work. It was thus placed high on the list of forbidden books. Tang Laihe is reported to have said, "I heard that in the 1590s the performance of the Hsi-hsiang chi...was still forbidden among [good] families." Gui Guang (1613-1673) called the work "a book teaching debauchery." On the other hand, the famous critic Jin Shengtan considered it silly to declare a book containing sex to be immoral, since "If we consider [sex] more carefully, what day is without it? What place is without it? Can we say that because there is [sex] between Heaven and Earth, therefore Heaven and Earth should be abolished?".