In Shakespeare's Macbeth, when Macduff arrives to collect King Duncan so that they may continue with Duncan's travels, pandemonium breaks out when it is realized that Duncan has been murdered. Macbeth says that when he saw Duncan dead, he lost his head. Who wouldn't?—he implies.
Here lay Duncan,
His silver skin laced with his golden blood,
...who could refrain,
That had a heart to love...
Macbeth notes that he is so overcome by fury that he kills the guards without thinking because he was so horrified by what "they" had done. The true reason Macbeth kills the guards is so that they cannot raise suspicion regarding the King's death—they cannot say they heard sounds in the night or that they felt drugged, etc.
The guards could raise doubts about how the King actually died, and this is a concern for Macbeth. He wants nothing to stand in his way of the throne. Fortuitously, Malcolm and Donalbain flee in fear of their lives. For Macbeth, what could be better than that he comes straight to the throne because his cousins have run away?
The only other thing Macbeth needs to be careful of is Banquo: he is the only person aware of the witches' prophecies for Macbeth, which would also raise suspicions of Macbeth's involvement, especially in that Duncan died under Macbeth's roof.