Oleksandr Zubkov gave the European champions a scare late in the first half when he halved the deficit after goals from Rodrygo and Vinicius Junior, but Carlo Ancelotti's side managed to navigate their way to another victory in Group F.
Real Madrid made the breakthrough in the 13th minute of the contest when Rodrygo battled his way to the edge of the Shakhtar box before finding the back of the net with a powerful finish.
Anatolii Trubin got a hand to the strike, but it was not enough to prevent the goal, with the reigning European champions making the perfect start in front of their own supporters.
Los Blancos remained on the front foot and doubled their advantage in the 28th minute when a brilliant team move ended with Rodrygo sliding a pass into Vinicius, who expertly picked out the far corner of the net.
Shakhtar had a lifeline before the interval, though, with Zubkov finding the back of the net with a brilliant volley after a brilliant cross from Bohdan Mykhaylichenko on the left.
The visitors had another half-chance early in the second period when Mykhaylo Mudryk broke into a dangerous position, but Ferland Mendy was across to make a brilliant last-ditch challenge.
Rodrygo was next to come close, with the attacker combining with Karim Benzema before releasing a strike in the 64th minute, but Trubin was on hand to make the save.
Benzema and Marco Asensio had chances to add to the scoring late on, but the former saw his effort saved by Trubin before the latter struck the post in stoppage time.
Real Madrid have not mathematically secured a spot in the knockout round of the competition, but they are six points clear of third-placed RB Leipzig with three games to play, while Shakhtar remain second in the section on four points.