Luke, like only a few other indivduals, believed that he could defeat the dark side from the inside. However, he had underestimated the power of the dark side, ignoring one of Yoda's most important lessons. Skywalker worked for the light side in the shadows just like Quinlan Vos had during the Clone Wars. And just like that Jedi Master, he found he was unable to break away from its snare once he was immersed too deeply in it. During this dark apprenticeship, Luke acquired two Imperial Sentinels, clones mutated into his dark side servants. Though he succeeded in covertly sabotaging several of Palpatine's plans including a World Devastator attack on Mon Calamari, he was too deep in darkness to think clearly.
When Leia arrived on Byss to rescue him, she succeeded only in getting herself captured, along with Han. However, Leia's light side presence allowed Luke to partially shake off the dark side, giving him the initiative to rebel against Palpatine fully. He aided the escape of her and Han and supplied them with the interface codes that controlled the World Devastators on Mon Calamari. He then turned to Palpatine.
In a failed assassination attempt, he marched into the cloning lab and smashed all the cloning tanks just after Palpatine's current body expired. However, before he could finish the job, Palpatine managed to transfer into one of the last living clones. When Luke attempted to subdue Palpatine, citing that his time as the Sith Lord's apprentice had taught him the Emperor's weaknesses, Palpatine scoffed at him and seized one of the lightsabers he kept in the lab. The two engaged in a quick lightsaber duel, but Luke fell before Palpatine's brutal sword work. Palpatine then traveled to Pinnacle Base in his flagship; Eclipse; bringing a broken Luke along. However, with the help of his sister Leia, Luke was able to fight back the darkness before it consumed him and turned against his master. Skywalker finally defeated Palpatine in single combat.