Following a brief setup scene the play begins with the appearance of two childhood friends: Leontes, King of Sicilia, and Polixenes, the King of Bohemia. Polixenes is visiting the kingdom of Sicilia, and is enjoying catching up with his old friend. However, after nine months, Polixenes yearns to return to his own kingdom to tend to affairs and see his son. Leontes desperately attempts to get Polixenes to stay longer, but is unsuccessful. Leontes then decides to send his wife, Queen Hermione, to try to convince Polixenes. Hermione agrees and with three short speeches is successful. Leontes is puzzled as to how Hermione convinced Polixenes so easily, and Leontes suddenly goes insane and suspects that his pregnant wife has been having an affair with Polixenes and that the child is a bastard. Leontes orders Camillo, a Sicilian Lord, to poison Polixenes. Camillo instead warns Polixenes and they both flee to Bohemia.
Furious at their escape, Leontes now publicly accuses his wife of infidelity, and declares that the child she is bearing must be illegitimate. He throws her in prison, over the protests of his nobles, and sends two of his lords, Cleomenes and Dion, to the Oracle at Delphi for what he is sure will be confirmation of his suspicions. Meanwhile, the queen gives birth to a girl, and her loyal friend Paulina takes the baby to the king, in the hopes that the sight of the child will soften his heart. He grows angrier, however, and orders Paulina's husband, Lord Antigonus, to take the child and abandon it in a desolate place. Cleomenes and Dion return from Delphi with word from the Oracle and find Hermione publicly and humiliatingly put on trial before the king. She asserts her innocence, and asks for the word of the Oracle to be read before the court. The Oracle states categorically that Hermione and Polixenes are innocent, Camillo an honest man, and that Leontes will have no heir until his lost daughter is found. Leontes shuns the news, refusing to believe it as the truth. As this news is revealed, word comes that Leontes' son, Mamillius, has died of a wasting sickness brought on by the accusations against his mother. Hermione, meanwhile, falls in a swoon, and is carried away by Paulina, who subsequently reports the queen's death to her heartbroken and repentant husband. Leontes vows to spend the rest of his days atoning for the loss of his son and his queen.
Antigonus, meanwhile, abandons the baby on the coast of Bohemia, reporting that Hermione appeared to him in a dream and bade him name the girl Perdita. He leaves a fardel (a bundle) by the baby containing gold and other trinkets which suggest that the baby is of noble blood. A violent storm suddenly appears, wrecking the ship on which Antigonus arrived. He wishes to take pity on the child, but is chased away in one of Shakespeare's most famous stage directions: "Exit, pursued by a bear." (It is not known whether Shakespeare used a real bear from the London bear-pits, or an actor in bear costume.) Fortunately, Perdita is rescued by a shepherd and his son, also known as "Clown."
"Time" enters and announces the passage of sixteen years. Camillo, now in the service of Polixenes, begs the Bohemian king to allow him to return to Sicilia. Polixenes refuses and reports to Camillo that his son, Prince Florizel, has fallen in love with a lowly shepherd girl: Perdita. He suggests to Camillo that, to take his mind off thoughts of home, they disguise themselves and attend the sheep-shearing feast where Florizel and Perdita will be betrothed. At the feast, hosted by the Old Shepherd who has prospered thanks to the gold in the fardel, the pedlar Autolycus picks the pocket of the Young Shepherd and, in various different guises, entertains the guests with bawdy songs and the trinkets he sells. Disguised, Polixenes and Camillo watch as Florizel (under the guise of a shepherd named Doricles) and Perdita are betrothed. Then, tearing off the disguise, Polixenes angrily intervenes, threatening the Old Shepherd and Perdita with torture and death and ordering his son never to see the shepherd's daughter again. With the aid of Camillo, however, who longs to see his native land again, Florizel and Perdita take ship for Sicilia, using the clothes of Autolycus as a disguise. They are joined in their voyage by the Old Shepherd and his son who are directed there by Autolycus.
In Sicilia, Leontes is still in mourning. Cleomenes and Dion plead with him to end his time of repentance because the kingdom needs an heir. Paulina, however, convinces the king to continue his penance until she alone finds him a wife. Florizel and Perdita arrive, and they are greeted effusively by Leontes. Florizel pretends to be on a diplomatic mission from his father, but his cover is blown when Polixenes and Camillo, too, arrive in Sicilia. The meeting and reconciliation of the kings and princes is reported by gentlemen of the Sicilian court: how the Old Shepherd raised Perdita, how Antigonus met his end, how Leontes was overjoyed at being reunited with his daughter, and how he begged Polixenes for forgiveness. The Old Shepherd and Young Shepherd, now made gentlemen by the kings, meet Autolycus, who asks them for their forgiveness for his roguery. Leontes, Polixenes, Camillo, Florizel and Perdita then go to Paulina's house in the country, where a statue of Hermione has been recently finished. The sight of his wife's form makes Leontes distraught, but then, to everyone's amazement, the statue shows signs of vitality; it is Hermione, restored to life. As the play ends, Perdita and Florizel are engaged, and the whole company celebrates the miracle. Despite this happy ending typical of Shakespeare's comedies and romances, the impression of the unjust death of young prince Mamillius lingers to the end, being an element of unredeemed tragedy, in addition to the years wasted in separation.