Why did L die in Death Note?

He died of a heart attack caused by Rem, who wrote his name in her Death Note to protect Misa from eventually being pegged as the second Kira, as was Light's plan all along.