The death of Polonius is pivotal. Hamlet kills him by stabbing him through the arras with his sword. Her father's death causes Ophelia to lose her mind. It also brings Polonius' son Laertes back from France seeking vengeance. Claudius persuades Laertes to turn his wrath on Hamlet and murder him in a fencing match. Ophelia's death may be either an accident or suicide. She drowns in a stream. Claudius prepares a poisoned goblet to offer Hamlet during the fencing match to make doubly sure that Hamlet will die. During the match, Laertes stabs Hamlet with an untipped foil which he has dipped in a deadly poison. Hamlet manages to switch foils with Laertes and stabs him with the poisoned one. Gertrude drinks from the goblet of poisoned wine before her husband Claudius can stop her. Both Hamlet and Laertes are dying. Laertes confesses that the foil Hamlet now is holding is poisoned and that King Claudius was responsible for the plot to kill Hamlet. Hamlet is enraged at this final treachery of his uncle. He stabs him with the same foil and also forces him to drink some of the remaining poisoned wine from the goblet. So Laertes, Gertrude, Claudius, and finally Hamlet all die in the last act. At about this point, ambassadors arrive from England to inform Claudius that Rosencrantz and Guildenstern have been executed as they believe he requested in the letter which was actually forged by Hamlet. So all the principal characters except Horatio are dead. Horatio tries to kill himself by drinking out of the poisoned goblet in order to follow his good friend in death; but Hamlet prevents him, saying:
Give me the cup. Let go! By heaven, I'll have't.
O God, Horatio, what a wounded name,
Things standing thus unknown, shall live behind me!
If thou didst ever hold me in thy heart,
Absent thee from felicity awhile,
And in this harsh world draw thy breath in pain,
To tell my story.
Polonius is killed by Hamlet while he is spying on Hamlet and his mother in Gertrude's bedchamber.
Ophelia becomes insane with grief. She falls into a stream and does not try to save herself from drowning.
Laertes is killed by Hamlet in the fencing match.
Hamlet is killed by Laertes in that same match.
Gertrude dies from drinking out of the poisoned goblet that Claudius has prepared for Hamlet. It is not clear whether she knows the wine is poisoned and is drinking it to save her son's life or whether she is just thirsty.
Claudius is killed by Hamlet with the poisoned foil and being forced to drink from the poisoned goblet.
Rosencrantz and Guildenstern have been beheaded by the English, who act on the written request they believe was brought directly from King Claudius but was actually forged by Hamlet aboard the ship headed for England.
Horatio remains alive in order to tell the whole story. He is the only one left alive who knows the truth from beginning to end will be able to exonerate Hamlet.
Fortinbras appears in the last act and may become the next king of Denmark, but he is not one of the principal characters.
The only people left standing in the court are really Horatio and a bunch of folks without names. Claudius is killed by Hamlet, as is Laertes. Hamlet is killed by Claudius through Laertes' poisoned sword, Gertrude drinks the poison in the cup meant for Hamlet, Rosencrantz and Guildenstern and Ophelia are already dead. Fortinbras is still alive and has shown up to clean up the mess and take over Denmark.
Ophelia killed herself not long after Hamlet killed her father Polonius and Rosencrantz and Guildenstern were killed on their trip to England which was supposed to end in Hamlet's death.