At the end of Hamlet, Laertes challenges Hamlet to a fencing contest, which Laertes and Claudius have already fixed so that Hamlet will die no matter what. Laertes has tipped his fencing foil with poison so that if he but scratches the prince, Hamlet will die of the poison. Claudius adds a poisoned pearl to a cup of wine so that, when Hamlet gets thirsty from the fighting, he will ingest poison in that way too.
During the fighting, Gertrude, Hamlet's mother, raises the poisoned cup to toast to her son, and though Claudius tells her not to drink, she does so anyway. He knows that she will die and that there is nothing to be done now to save her. Laertes and Hamlet resume their contest, and Laertes wounds Hamlet, but they switch weapons during their scuffle, and Hamlet wounds Laertes with the poisoned blade. At the same time, Gertrude falls to the floor, and she cries out, saying that it is the drink that has killed her. After the queen dies, Laertes confesses everything. When Hamlet learns of Claudius's role in this, he wounds the king with the poisoned foil and forces some of the poisoned wine down his throat. The king dies, followed by Laertes.
Hamlet and Horatio speak during Hamlet's final moments, and Horatio would prefer to drink the poison himself so that he could follow Hamlet to death, but Hamlet will not allow him to do so. Hamlet directs Horatio to tell the story of what happened here, and so Hamlet dies. Young Fortinbras and ambassadors from England arrive, and when Fortinbras sees that the entire Danish royal family is dead, he says,
With sorrow I embrace my fortune.
I have some rights of memory in this kingdom,
Which now to claim my vantage doth invite me.
(act 5, scene 2, lines 431–433)
In other words, Fortinbras has some old claim to the Danish throne, and he will rule Denmark now, restoring some order to the kingdom after all of the corruption and death.