Dylan Cozens had a goal and two assists, JJ Peterka scored twice, and Alex Tuch had a goal and an assist for the Sabres (22-23-4), who have won two straight. Casey Mittelstadt had two assists, and Ukko-Pekka Luukkonen made 23 saves.
"I don't think we ever wavered in our confidence and our energy," Tuch said. "Our style of play, I don't think, really changed. We just tightened up a few areas, made a couple better plays with the puck and we were just a little stronger in puck battles."
William Eklund had two assists, and Kaapo Kahkonen made 31 saves for the Sharks (13-32-4), who ended their three-game winning streak.
"A good start by us, scored on some chances that we got. But I don't think we did enough around their net," San Jose captain Logan Couture said. "Didn't make it as hard on the goaltender as we would have liked to, and gave them a few chances in our defensive zone."
Peterka cut the lead to 2-1 at 14:14 of the first period, putting in a rebound in front off Cozens’ wraparound attempt.
Jordan Greenway put in a cross-crease pass from Tuch to tie it 2-2 at 18:01.
Tuch gave Buffalo a 3-2 lead at 1:36 of the second period with a wrist shot from the right circle past a screened Kahkonen.
Peterka's second goal, a one-timer from the right circle on a 3-on-2 rush, made it 4-2 at 4:33 of the third period.