Scene 1: Two gravediggers make Ophelia's grave. Hamlet arrives and watches as the gravediggers remove skulls to make room for the fresh grave. Hamlet wonders whose skulls they were. The gravediggers do not recognize Hamlet who asks who the grave is for. They answer him cryptically. The gravediggers then tell him the skull belongs to Yorrick, a former court jester. He regrets that all humans, including kings, will eventually turn to dust. Hamlet, in one of literature's more famous apostrophes, converses with Yorrick's skull. The funeral procession arrives. Hamlet realizes it's Ophelia who has died. Laertes becomes furious with the priest for not giving Ophelia a proper Christian burial on account of her suicide.
Laertes jumps in the grave to hold his sister one more time. Hamlet bursts forth, jumps in the grave, and declares his love for Ophelia is greater than that of 40,000 brothers. The two fight. Claudius and the Queen declare that Hamlet is mad. Claudius calms Laertes by reminding him of their plan for revenge. Hamlet's fit of passion leads the reader to also question just how much of Hamlet's madness is feigned.
Scene 2: Hamlet relates to Horatio how he escaped execution by having Rosencrantz and Guildenstern executed instead. He feels bad over his confrontation with Laertes, recognizing their similar situations. Osric arrives and informs Hamlet that the king has arranged a dual between Hamlet and Laertes. Claudius claims that if Hamlet scores the first or second hit he will drink to his health, throw in a victory pearl (actually poison), and give the drink to Hamlet. Hamlet refuses the drink. Gertrude drinks it instead. Laertes' sword is poisoned. He wounds Hamlet. Hamlet wounds Laertes with the same sword. The queen dies. Laertes informs Hamlet about the poisoned sword and that they will both die shortly. Hamlet runs the sword through Claudius and forces him to drink the poison (you can never be too sure about these things). Hamlet and Laertes forgive each other and die.
Fortinbras arrives. Before dying, Hamlet tells Horatio to live and tell his story and to make Fortinbras king. Fortinbras asks for Hamlet to be carried away as a soldier.