It was Carter's first four-goal game in the NHL and seventh hat trick. His last was March 29, 2018, for the Los Angeles Kings against the Arizona Coyotes.
"I don't know what happened out there, to be honest with you," Carter said. "The puck was following me all night."
Sidney Crosby had a goal and an assist, Jared McCann had a goal and two assists, and Tristan Jarry made 19 saves for Pittsburgh (36-16-3), which has won eight of 10. The Penguins are first in the eight-team MassMutual East Division, two points ahead of the second-place Washington Capitals.
Drake Caggiula scored twice, and Michael Houser made 26 saves for Buffalo (15-33-7), which has lost five of seven will finish last in the NHL standings. The 28-year-old goalie won his first two NHL starts, against the New York Islanders on Monday and Tuesday, after not starting a professional game since March 7, 2020, in the ECHL.
The teams play here again Saturday in the regular-season finale for each.
"I like our confidence," Sabres coach Don Granato said. "I like our thought that we can go score, but we didn't know what we should respect enough. … We didn't respect the fact that we're playing against a team that, if we don't take care of things the right way, the puck the right way, they can score quick and convert quick."
The Penguins, Capitals, Boston Bruins and Islanders have clinched the four Stanley Cup Playoff berths from the eight-team division.
After Caggiula gave Buffalo a 1-0 lead with a snap shot at 2:45 of the first period, Carter scored two goals 1:42 apart to put Pittsburgh ahead.
Rasmus Ristolainen nearly denied Carter his first goal, when a shot got past Houser before Ristolainen scooped it away as it crossed the goal line at 9:57. Play continued for 54 seconds before being stopped, and it was ruled a goal after a review, tying the game 1-1.
Carter gave the Penguins a 2-1 lead with a one-timer on the power play at 11:39.
"There aren't too many four-goal games around the whole League," Penguins coach Mike Sullivan said. "It's hard. It's hard to score goals in this league, never mind four in a game. It doesn't happen very often. It's a huge accomplishment. He had a terrific game for us."