The play opens soon after the death of the king of Denmark. Claudius, the king's brother, has claimed the throne and taken his sister-in-law—Hamlet's mother, Gertrude—as his queen. These events have left Prince Hamlet distraught and grieving. As the story begins, the ghost of King Hamlet appears in Elsinore, Denmark's royal castle. Sentinels who witness the ghost alert Horatio, who, upon seeing the ghost himself, goes to tell his dear friend Hamlet.
Hamlet's world is shaken anew when Horatio tells him that he has seen a ghost resembling his father. When Hamlet joins Horatio (Act 1, Scene 4) and sees the ghost himself, he is terrified. The ghost tells Hamlet that he has been murdered and that Claudius poisoned him. He commands Hamlet to avenge his death but insists that he not harm his mother. Hamlet questions whether the ghost is real, but his mourning is now compounded by rage.
Earlier, Hamlet had returned from his studies in Germany after learning of his father's death. Already in mourning, Hamlet is pushed deeper into despair by his mother's hasty second marriage. It is clear from his soliloquy in Act 2 that he is confused that his mother could disregard the sorrow of losing her husband and enter into marriage with his brother.
Meanwhile, Claudius seeks some semblance of normalcy for Denmark. Holding court one afternoon, Claudius draws attention to young Prince Fortinbras of Norway, who is raising an army against Denmark. Fortinbras seeks to avenge the death of his father, who had died in battle against King Hamlet some years before. Claudius does not see the parallel between that young prince and his nephew, nor does he take a note of caution from the situation.
Claudius casts a more fatherly eye on Laertes, son of his counselor Polonius, who seeks the king's blessing for his to return to France, which Claudius approves. Claudius next chastises Hamlet for the unseemly way in which he mourns for his father, after which he and Hamlet's mother deny his desire to return to Germany, insisting he stay in Elsinore.
As Laertes prepares to leave for France, he confronts his sister, Ophelia, about her relationship with Prince Hamlet. He warns her not to take Hamlet's affection seriously. Her father, Polonius, overhears; when Laertes has gone, he agrees with his son's advice and orders Ophelia to avoid Hamlet. Heartbroken, Ophelia says she will obey.
Sometime later, Ophelia tells Polonius of a distressing encounter with Prince Hamlet. She says Hamlet came to her looking bewildered. Polonius thinks Hamlet's love for Ophelia is driving him mad and decides he must tell the king and queen of this occurrence.
When Polonius visits the king and queen, they are already meeting with Rosencrantz and Guildenstern, two of Hamlet's childhood friends, in an attempt to figure out Hamlet's strange behavior. Also at hand are Voltemand and Cornelius, the ambassadors Claudius sent to Norway, who are reporting that "Old Norway" has commanded Fortinbras to abandon aggression against Denmark. Fortinbras vows obedience and will turn his attention to Poland. Finally, Polonius relates the story of Hamlet's encounter with Ophelia; he tells the king and queen that he believes Hamlet's love for Ophelia has driven him mad.
Hamlet meets Rosencrantz and Guildenstern and becomes suspicious of their presence in Elsinore. When they tell him that a company of players (actors) has arrived, he is excited. Hamlet seeks out the actors and asks them to perform a version of the play The Murder of Gonzago. By inserting a scene depicting his father's murder, Hamlet hopes his revised play, The Mousetrap, will catch the king in his guilt.
Claudius and Polonius plan to eavesdrop on Ophelia and Hamlet. As they hide nearby, Hamlet comes upon Ophelia and they chat. However, he quickly becomes suspicious of Ophelia's motives when she tries to return gifts he gave her. He rages wildly with sorrow and disappointment and tells Ophelia to "get thee to a nunnery" before leaving her.
Ophelia is devastated; Claudius and Polonius are shocked. Claudius realizes Hamlet poses a threat to him. He decides to send Hamlet to England to be rid of him. Polonius agrees but suggests one last try: have Gertrude talk with him after the play that evening, and he, Polonius, will eavesdrop on the conversation.
That evening the theater company performs for Claudius's court. As the players reenact the scene of the king being poisoned in the garden—as the ghost told Prince Hamlet—Claudius flies into a panicked rage, halting the play and fleeing the room. Hamlet, with Horatio beside him, takes this as an admission of guilt.
After the play, Claudius meets with Rosencrantz and Guildenstern and tasks them with taking Hamlet to England. When they leave to find Hamlet, Claudius admits to King Hamlet's murder in a soliloquy. He attempts to pray, but finds he cannot repent, because he is unwilling to give up the rewards gained from the murder: the throne and his wife. Hamlet passes and sees Claudius on his knees. He thinks how easy it would be to kill his uncle then and there, but decides not to. Hamlet believes that to kill Claudius while he is in prayer would grant him entry to Heaven, which Hamlet does not want.
Hamlet meets with Gertrude in her chambers; Polonius hides nearby. Hamlet confronts Gertrude about her part in King Hamlet's death. When she cries out, Polonius shouts, revealing his presence, but not his identity. Believing that Claudius is hiding there, Hamlet stabs Polonius through the tapestry and kills him. Hamlet leaves, dragging Polonius's body with him. The encounter convinces Gertrude that her son is indeed mad.
Gertrude goes to tell Claudius of her meeting with Hamlet and of Polonius's death. Once he is alone, Claudius reveals that Hamlet is also soon to die; the documents he is sending with the ship call for Hamlet's execution.
As Hamlet, Rosencrantz, and Guildenstern head to the boat, they spy Fortinbras and his army en route to Poland. Hamlet is struck by the contrast between himself and young Fortinbras. He sees Fortinbras's ability to act—instead of think—as a mark of greatness. When contrasting himself with Fortinbras, Hamlet finds himself wanting.
Ophelia asks to meet with Gertrude and Claudius, and they realize that she has gone mad with grief. Laertes, back from France, storms in to see the king and queen and is heartbroken to find Ophelia in such a confused condition. Claudius convinces Laertes they had nothing to do with Polonius's death or Ophelia's madness. He counsels Laertes to be patient and encourages him to follow his counsel to exact his revenge. Laertes consents.
A messenger finds Horatio, bearing letters from Hamlet to Horatio and to Claudius. Hamlet's letter informs Horatio that he is back in Denmark and has much to tell him about his failed trip to England. He asks that Horatio lead the messenger to the king to deliver his letters to him. After that, the messenger will lead Horatio to him.
Claudius and Laertes are together when the king receives word of Hamlet's return. They plot a fencing duel between Hamlet and Laertes, with Laertes using a poison-tipped foil (sword). As a backup, they plan to have a poisoned cup of wine ready for Hamlet to drink. They intend to give Laertes his revenge without putting either of them in harm's way. As they conclude their meeting, Gertrude brings word that Ophelia has drowned.
Hamlet and Horatio meet in the graveyard where Ophelia is about to be buried. As the funeral procession gathers around her grave, the grief-stricken Laertes jumps into her grave and proclaims his love. Hamlet, overcome in the moment, follows, and they fight. Horatio and the other mourners separate the two as Hamlet boldly proclaims his love for Ophelia.
When Horaito and Hamlet leave the graveyard and enter the castle, Osric, one of Claudius's courtiers, tells Hamlet that Claudius has wagered on Hamlet to win a fencing match against Laertes. Hamlet accepts the challenge and says he will strive to win on the king's behalf.
The duel begins. Hamlet strikes Laertes twice and Gertrude drinks to Hamlet's health, unknowingly drinking the poisoned wine. Alarmed by the way the competition is going, Laertes finally strikes Hamlet, they scuffle, and the foils are exchanged. Hamlet's next hit on Laertes poisons him.
Suddenly, the queen collapses. As she dies, Laertes reveals to Hamlet that both of them have also been poisoned by the foil now in Hamlet's hands. Laertes reveals the plot to everyone, proclaiming that the king is to blame. Before he closes his eyes for the last time, he and Hamlet exchange forgiveness.
Enraged, Hamlet kills Claudius—stabbing him with the poisoned foil and forcing him to drink the rest of the poisoned wine. Hamlet watches him die, but he himself is soon to follow. As the prince approaches death, he begs Horatio to carry his story to the world.
Young Fortinbras, returning from Poland, arrives to find the gruesome scene—Hamlet, Laertes, Gertrude, and Claudius all dead—and to hear Horatio's explanation.