Palpatine was in trouble for about a minute after Anakin Skywalker died on Mustafar. But he was still Darth Sidious, and Darth Sidious always had a back-up plan.
He'd already used the genetic material of the bounty hunter Jango Fett to create the clone army that served as the basis for the Empire's Storm Troopers. The only thing he needed from the once and future Darth Vader was his concentration of midi-chlorians, which is to say the unlimited power he'd craved for a thousand years.
Upon his death, Skywalker effectively relinquished the midi-chlorians to his master. Thankfully, even though he himself could not directly absorb the conduits of the Force, Palpatine had the opportunity to channel them in a new direction, which of course was what he did. He had a clone of Fett at his side at all times. Fett had asked for an unaltered clone to raise as a son, but the cloners had also granted Palpatine, through the original request of Sifo-Dyas, another. The clone army itself was modified to be more docile. Palpatine's sense of control was less literal than that. He thrived more on emotion than intellect but needing both in order to effectively advance the cause of the Dark Side.
Darth Vader, then, was a clone of Jango Fett all along, implanted with the memories of Anakin Skywalker.
On the day Skywalker's son murdered Palpatine, Darth Sidious was once again in trouble, but again for only about a minute. He transferred his sizable number of midi-chlorians, as well as a part of himself, to the young Jedi.
The effect was not immediately apparent. It was only the death of Vader, again, at the same time that prevented this final back-up plan from succeeding. For a time, the young Skywalker considered turning to the Dark Side after all, a temptation he'd considered as part of his quest to redeem his father, something that only made sense from the warped perspective of the Sith, who only think in absolute terms. Ironically, balance had been lost within the Force after the Jedi unwittingly began behaving in the same way.
The difference, the saving grace, wasn't in the essence of Anakin Skywalker that was transferred to his son, but Jango Fett's.
Fett's desire for offspring was something Palpatine hadn't properly considered. The elder Skywalker had never considered such things. His love was for a mother, a wife, someone to share his life with, to depend on, not to see it continue beyond him. He had always thought in terms of the present. Fett was different. He had been a cold man, but in truth he'd spent his life running away from a nightmare but with a constant hope that he could still be redeemed.
You'll notice the theme of redemption, too.
Luke Skywalker overcame Palpatine's corruption because of his restlessness. It was a trait he shared with his father, but of a different kind. The elder Skywalker yearned for an improvement to his life, whereas the younger sought...adventure. Jango Fett's life had been an endless adventure. The combination of Fett and Vader had created the balance needed to fulfill a prophecy and ensure its lasting success, no matter the desperate dying acts of its greatest threat.
All of that happened before Palpatine even died. It played out in Luke's mind, a vision he had as he looked at his dying father, realizing what was happening, what might happen. He saw Jango and Boba Fett, too. It was in this moment he realized that he had inadvertently caused Boba's death. It was mourning the Fetts that broke the spell.
In the days and months to come, Luke hoped he could honor both his fathers.