Evan Bouchard gave the Oilers a 1-0 lead at 12:47 of the first period. He took a pass from McDavid before skating to the top of the right face-off circle for a wrist shot.
"That was big for us. We really wanted home-ice advantage," Bouchard said. "I think it's huge for us going into the playoffs. To play a game like that against a team like that, I think it was awesome."
Bouchard had a goal overturned at 1:58 of the second period when the Penguins challenged for offside.
Carter tied it 1-1 at 5:23, chipping in a shot past a diving Smith after a slap shot from Mike Matheson bounced off the end boards.
"Confidence is not going to just come all of a sudden," Pittsburgh defenseman Marcus Pettersson said. "I think when you put a couple of shifts together in the game, you get confidence that way. I think we've got to do that in the last game (against the Columbus Blue Jackets on Friday) and really find it. Because we know we have it in the room."
Kane answered 25 seconds later, putting Edmonton in front 2-1 at 5:48. He took a one-timer set up by a backhand pass through the slot from Kailer Yamamoto for his sixth goal in four games.
Zach Hyman made it 3-1 with a power-play goal at 4:08 of the third period, scoring from just outside the crease on the rebound of a Ryan Nugent-Hopkins shot.
McDavid pushed the lead to 4-1 at 9:13, skating through the left circle past Carter before scoring on a wrist shot from a sharp angle. He has 12 points (two goals, 10 assists) in his past four games and leads the NHL with 122 points (44 goals, 78 assists).
"Quiet four-point night? Loud four-point night? I don't know. It's just normal, right?" Hyman said of McDavid. "Just such a dynamic player. Best player in the world, right? So that's what you expect and that's what you get. I'm glad he's with us. I'm glad I'm here."