In a process technically called autotomy:
Once the team found one self-severed individual, they went about investigating why, and precisely how, that breakage occurred. These observations included attempts to induce a self-beheading, by imitating the sort of cursory nips a marine predator would make on the slug in the wild (perhaps, they guessed, the slug parting with its body was similar to a fighter jet pilot using an ejector seat)…
Though the true nature of the autotomy remains unknown, the team was able to induce autonomy in all but one slug within a day. In the paper, Mitoh’s team suggested that autotomy in the wild could happen in Elysia atroviridis because the slug is regularly encumbered with planktonic parasites—perhaps leaving a parasite-ridden body behind to grow a new one is the easiest way of dealing with the infestation.Isaac Schultz, “These Slugs Cut Off Their Own Heads When They Want a New Body” at Gizmodo
The paper is open access.
The bodies do not grow new heads. The slug head can live without a heart for some time because it breathes through the skin.
Note: These are the same creatures that grab chloroplasts from plants and photosynthesize when short of food — a remarkable form of horizontal gene transfer.