Hamlet tells Horatio what happened while he was out of Denmark: he was on the ship to England, and having a restless night when, in a bout of rash indiscretion (which he now notes is sometimes a Godsend) was inspired to check out Claudius's letter in Rosencrantz and Guildenstern's pack.
He stole the letter and went off to read it in his room.
Forgetting his manners in the midst of his fears, Hamlet broke the letter's seal. Within it, he found some paltry excuses to the effect that, for the health and wellbeing of both England and Denmark, Hamlet had to be killed immediately.
Shocked, Hamlet altered the letter to read as great poetry written in a beautiful hand, ending it to the effect that upon their arrival, the bearer of this letter (Rosencrantz and Guildenstern) should be immediately put to death, without any time to confess and beg absolution of their sins.
Hamlet even sealed the new letter with his father's own signet (a stamp-like object with a design relating to one's title or authority, often on a ring, used to seal official letters) which he conveniently had in his purse.
As luck would have it, the next day was the great sea fight where Hamlet ran off with the pirates. Horatio and the audience know the rest.
Horatio devotes a line to their school buddies, simply stating, "Rosencrantz and Guildenstern go to it [death]."
He's giving Hamlet a chance to be like, "Sorry I killed our friends in a manner that will damn them to eternal Hell," but instead Hamlet announces those two rats are nowhere near his conscience – he's not worried about having killed them because they made their own fate. They're collateral damage, which is to be expected in a battle between two great forces (Hamlet and Claudius, presumably).
Hamlet now reasons: Claudius has tried to kill him; Claudius killed his father; Claudius "whored" his mother; and Claudius deliberately stands in the way of Hamlet's access to the crown of Denmark. As Claudius generally tried to ruin Hamlet's life in every way possible, it seems that Hamlet can now pay him back. If anything, he would be wrong to not kill Claudius, as he'd only do more harm with time.
Now that we know Hamlet can revenge himself on Claudius in "perfect conscience," Hamlet says he's sorry Laertes got caught up in the whole thing. He's actually going to try to make up with him.
Just then, Oscric, a ridiculous member of the court, enters to ask Hamlet if he is willing to fight a friendly duel with Laertes based on a bet. King Claudius has bet six fine horses, six fine French swords, and three beautiful carriages, on the odds that Laertes wouldn't get more than three hits in over Hamlet in a fencing match.
The only other little detail is that the duel has to happen right now. Hamlet agrees to go through with the fight, but Horatio insists that if he doesn't feel up to it, he should just skip it.
Hamlet, a regular fatalist, says that death will come when it comes.
The court assembles to watch the duel, including the King (poisoned beverage in hand!) and Queen.
Hamlet, shockingly, is the picture of quiet gentleness.
Claudius offers to put Laertes's hand into Hamlet's, and Hamlet takes the opportunity to apologize for the wrong he's done, blaming it on his madness. Hamlet declares it was not he at all that wronged Laertes; in fact, it was solely his madness. Hamlet declares that Hamlet himself is but a member of the group of people who is wronged, and that he is a mortal enemy of Hamlet's madness.
Laertes hears all of this. He says he's satisfied by Hamlet's apology, but he'd look like a be a bit of a fool if he just responded, "Thanks for apologizing for killing my dad" and left it at that. Laertes thinks his name will have to be cleared by a more proper method, one that won't stain his reputation. Until then, though, Laertes is happy to have Hamlet's love.
The two young men thus agree the fencing match will be a friendly little one (except for the multiple plans Laertes has to murder Hamlet).
Just before the duel begins, Hamlet declares himself to be the weaker player, but Claudius declares he doesn't mind..
As Osric presents the men the swords, Laertes quibbles, dismissing one as being too heavy. He's clearly picking through the swords, seeming to be choosy, when actually we know he's searching for the sharpened, poisoned sword. (This way we know he's still going on with his plan, in spite of the seeming truce).
Hamlet is much less choosy than Laertes; he's satisfied and takes a sword after asking only one question about whether the swords are all the same length (which matters for fighting, but not for pulling off a dastardly plan).
Claudius also makes a big show, saying cannons will fire and the King will drink to Hamlet's good hits.
As Hamlet and Laertes cross swords, Hamlet scores the first few points. Claudius offers him the poisoned goblet of wine, but Hamlet declines and keeps fighting. Gertrude then toasts Hamlet with the poisoned wine, and the Queen drinks.
Claudius warned her not to drink, but of course "too late." Meanwhile, Laertes is battling with himself in an aside, wondering if it's not against his conscience to strike Hamlet with the poisoned sword.
Laertes ends up striking Hamlet, and in a scuffle, the two men somehow exchange swords.
Hamlet wounds Laertes unwittingly with the fatal sword. They both fall right around the time as the Queen.
Laertes declares it fitting that he die by his own sword's treachery.
The Queen cries out, and Claudius tries to pass off her falling as a fun game she likes to play when she watches sword matches. The Queen, finally coming to her senses, declares above the uproar that the drink was poisoned.
Hamlet declares treachery is afoot.
Laertes admits the treachery is present right there in the room. He announces that he and Hamlet will expire within a half hour from poisoned swords, and that Gertrude will beat them to death by a few minutes.
Laertes immediately declares, in so many words, "It's all Claudius's fault! Claudius did it!"
Hamlet, always thinking quickly, grabs the poisoned sword and stabs Claudius. The people all shout out that it's treason.
In a violent fit, Hamlet also forces Claudius to drink the rest of the wine.
As Laertes lays dying, sprawled out on the cold palace floor, he asks for Hamlet's forgiveness. He adds that Hamlet isn't any more responsible for his death (and Polonius's) than Laertes will be for Hamlet's.
Laertes dies.
Hamlet, realizing his time is short, calls Horatio to him. He says he doesn't have enough time to tell the story himself, but Horatio should explain to the world what just happened.
Horatio says he's more Roman than Dane (citing Romans' tendency to kill themselves at their friends' deaths), but Hamlet begs him to lay off the suicide talk. Hamlet wants Horatio to live so that his story can be told through him.
Hamlet then hears the sound of approaching soldiers: it's Fortinbras! And his army! Returning victorious from his battle with Poland!
Hamlet opens his final speech with, "O, I die."
Hamlet declares Fortinbras should become the next King of Denmark, probably because everyone in Denmark is dead. "The rest is silence," he says, and dies.
Then Horatio talks about Hamlet's noble heart and how he hopes lovely little angels will bring the sweet prince to his rest.
Then there's lots of drumming as Fortinbras enters with the English ambassadors. Fortinbras is puzzled by all of the dead bodies strewn about.
The English ambassadors say they've just come to report that Rosencrantz and Guildenstern have been killed, according to orders.
Everyone is appropriately shocked. Horatio promises to explain the entire bloody story.
Fortinbras says it's really all too bad, but really he has rights to the throne, and since it's kind of empty, he'll just be settling up there to hear the story.
Fortinbras orders Hamlet to be given a fine burial with the rites of war and soldier's music, as Fortinbras is sure that Hamlet would've been a good king.