The daughter's prediction comes true, and this is the beginning of the opera. When the king learns that the daughter had wisely known what his actions would be he sends for her to come before him. He tells her she has "talked a noose around her neck" and will give her two choices for how to save her life. She can either gamble for it, or answer 3 riddles.
The wise daughter chooses to answer the 3 riddles, and saves her life. The king makes her his queen and all seems happy.
The opera is only half over though. Three scoundrels have stirred up some trouble between the owner of a donkey and a mule. One morning they found a baby donkey between the two beasts, and the mule owner ridiculously thought it could be his. The king agrees that since the baby was closer to the mule it must belong to it. The queen overhears this and sets up the donkey owner to show the king the error of his foolish judgment. The king realizes that his new wife is mocking him and working against his decision and he sends her away with a large box and tells her to take whatever she wishes and leave. The queen drugs her husband with opiates in his wine, and the opera happily ends with him waking up inside the box, and acknowledging that she truly is a wise woman. She contradicts him and says that no one who loves can be truly wise. Also at the end, the peasant finds the golden pestle which got him sent to the dungeons in the first place.