A ghost resembling the recently-deceased King of Denmark stalks the ramparts of Elsinore, Denmark’s royal castle, over the course of several nights, setting all the castle’s guardsmen on edge. The terrified sentinels Marcellus, Francisco, and Barnardo convince a skeptical nobleman, Horatio, to watch along with them one night. When Horatio sees the ghost, he decides they should tell prince Hamlet—his closest friend and the dead king's son. Hamlet is also the nephew of the present king, Claudius, who not only assumed his dead brother's crown but also married the king’s widow, Gertrude. Claudius seems to be an able king, easily handling the threat of the Norwegian prince Fortinbras, who is seeking to take back the lands his own father lost in battle with Hamlet’s father. Hamlet, however, cannot accept his uncle’s rule, furious as he is about Gertrude's marriage to Claudius, and resentful of both his mother and his uncle for besmirching his father’s memory with their union. Hamlet agrees to meet the ghost, and as he speaks with it, it claims to be the spirit of his father. The ghost reveals that he did not die of natural causes, but rather was poisoned by Claudius. Hamlet, newly enraged, quickly accepts the ghost's command to seek revenge.
As the days go by, however, Hamlet is uncertain if what the ghost said is true, and struggles to decide whether he should actually kill his uncle. He delays his revenge and begins to act half-mad, contemplates suicide, and becomes furious at all women. He tells himself that his madness is a front which will allow him to investigate his uncle without the king realizing Hamlet is onto him, but as Hamlet investigates his own existential and moral center, his thoughts begin to tend toward serious distress, if not full-blown madness. The king’s obsequious old councilor, Polonius, begins to believe that Hamlet's behavior is tied to his affections for Ophelia, Polonius’s daughter. Claudius and Gertrude, unsatisfied with Polonius’s assessment, summon two of Hamlet's old school friends, Rosencrantz and Guildenstern, to try to find out what's wrong with him. As Polonius develops a plot to spy on a meeting between Hamlet and Ophelia—using Ophelia as a knowing pawn—Hamlet develops a plot of his own: to have a recently-arrived troupe of actors put on a play that resembles Claudius’s alleged murder of King Hamlet, and watch Claudius’s reaction. Hamlet decides that if Claudius reacts in a way that marks him as truly guilty, he will be able to avenge his father’s death without any moral doubts—in other words, he’ll have no excuse not to act decisively and kill the king.
Polonius and Claudius successfully spy on the meeting between Ophelia and Hamlet, during which Ophelia attempts to return gifts and letters Hamlet has given her over an undetermined amount of time—suggesting that Ophelia and Hamlet have had a romantic and perhaps sexual relationship for a while. Hamlet flies into a rage against women and marriage, claiming that women only breed sinners and ordering Ophelia to get herself to a nunnery and hide herself away from men. Claudius concludes Hamlet neither loves Ophelia, nor is he mad. Seeing Hamlet’s increasing instability as a threat, Claudius decides to send him away to England, where he will be less of a nuisance. At the play that night, however, as the actors perform a scene which mirrors the events of King Hamlet’s murder, Claudius runs from the room and thus proves his guilt in Hamlet’s eyes. Hamlet’s mother, Gertrude, angry with Hamlet’s embarrassing behavior at the play, summons him to her quarters to talk to him about what’s going on. Hamlet nearly gets his chance for revenge when, on the way to see Gertrude, he comes upon Claudius, alone and praying in a chamber. Hamlet holds off, however—if Claudius is praying as he dies, then his soul might go to heaven. Even after determining Claudius’s guilt through his intricate plot, Hamlet is unable to take action. In Gertrude's room, Hamlet berates his mother for marrying Claudius so aggressively that she thinks he might kill her. The ghost of Hamlet’s father appears to Hamlet again, but Gertrude claims not to be able to see it, and cries out that her son is truly mad. Polonius, who is spying on the meeting from behind a tapestry, calls for help. Hamlet thinks Polonius is Claudius and stabs him through the tapestry, killing him.
Claiming that he wants to protect Hamlet from punishment for killing Polonius, Claudius sends Hamlet to England with Rosencrantz and Guildenstern. Claudius’s real motivation, however, is to have Hamlet killed—he sends Rosencrantz and Guildenstern onward with a letter asking the King of England, Denmark’s ally, to execute Hamlet on sight. Meanwhile, Polonius’s son, Laertes, returns to Denmark from his studies in France to avenge his father's death. He finds that his sister, Ophelia, has gone insane with grief over her father’s death (and Hamlet’s rejection of her), and watches as she puts on a macabre and yet spellbinding display of singing old nursery rhymes alongside bawdy barroom songs, all the while passing out invisible “flowers” to the members of court. Claudius convinces Laertes that Polonius’s death—and Ophelia’s madness—are both Hamlet's fault. When news arrives that a pirate attack has allowed Hamlet to escape back to Denmark, Claudius comes up with a new plot in which a supposedly friendly duel between Hamlet and Laertes will actually be a trap—Laertes’s rapier will be poisoned. As a backup, Claudius will also poison some wine that he'll give to Hamlet if he wins.
Ophelia drowns in an apparent suicide, and a funeral is arranged for her. Even though suicides are not supposed to be given proper Christian burials, according to a pair of gravediggers preparing her grave, Ophelia will be buried with a limited set of rites since she is a noblewoman. Hamlet arrives back at Elsinore to find the gravediggers at work. As he observes them doing their morbid tasks merrily, he watches as they casually toss out the skull of Yorick, his father’s old court jester. Hamlet’s existentialism—and nihilism—reach new peaks as he looks at the skull, realizing that all living souls (be they great or common, good or evil) reach the same ends. When Hamlet realizes that it is Ophelia being buried, he bursts onto her memorial service, arguing that he loved her best of anyone—even as Laertes, stricken with grief, throws himself into his sister’s grave.
Back at the castle, Hamlet tells Horatio of his exploits on the ocean, revealing that he discovered Claudius’s plot and forged a letter in Claudius’s handwriting ordering the execution of Rosencrantz and Guildenstern instead of him, ensuring that the pair will be killed on sight when they reach England. When a courtier named Osric brings news of Laertes’s challenge to a duel, Hamlet bravely accepts. Horatio warns Hamlet that he has a bad feeling about the match, but Hamlet tells Horatio that he no longer cares whether he lives or dies—he wants to leave his fate up to God. During the match, Gertrude drinks to Hamlet's success from the poisoned glass of wine before Claudius can stop her. Laertes then wounds Hamlet with the poisoned blade, but in the scuffle they exchange swords and Hamlet wounds Laertes. Gertrude falls, saying the wine was poisoned, and dies. Laertes, realizing that he, too, is doomed by his own poison, reveals Claudius’s treachery. Hamlet kills Claudius by stabbing him with the poisoned sword and pouring wine down the man’s throat, poisoning him just as Claudius poisoned Hamlet’s father. Hamlet and Laertes forgive each another just before Laertes collapses and dies. As Hamlet dies, he hears the drums of Fortinbras's army marching through Denmark after a battle with the Polish, and tells Horatio, with his dying breath, that Fortinbras should be the one to ascend to the throne as the next King of Denmark. Looking around at the mess of spilled wine and bloody bodies, Hamlet charges Horatio with telling the world the full truth of Hamlet’s story. He dies, and Horatio bids the “sweet prince” goodbye. Fortinbras enters with a pair of ambassadors from England, who announce that Rosencrantz and Guildenstern are dead. Horatio begins to tell Hamlet's story, and Fortinbras orders Hamlet's body to be lifted up on a bier and displayed with the due honor and glory of a soldier.