Tage Thompson turned the puck over to Terry at center ice, who skated it in and put a backhand shot top shelf over Buffalo goalie Alex Lyon's blocker for the win.
Terry scored twice, Chris Kreider, Jackson LaCombe, Beckett Sennecke each had a goal and an assist, Leo Carlsson had two assists, and Ville Husso made 24 saves for the Ducks (39-27-4), who stretched their point streak to four games (3-0-1).
Owen Power and Zach Benson each tallied a goal and an assist, Rasmus Dahlin had two assists, and Alex Lyon made 27 saves for Buffalo (44-20-7), which rallied from a two goal, third period deficit to stretch its point streak to five games (4-0-1).
The Sabres took a 1-0 lead at 3:36 of the first period. Power made a no-look backhand pass from the end boards to Alex Tuch in the bottom of the right face-off circle and Tuch scored with a snap shot.
The Ducks came back with two power-play goals in a 2:56 span. Kreider scored first with a snap shot from the right circle off a cross-ice feed from Carlsson to tie it 1-1 at 9:27, then LaCombe hit the net with a wrist shot from just inside the blue line for a 2-1 lead at 12:23.
Josh Doan finished off a 2-on-1 thanks to a feed from Noah Ostlund to tie it 2-2 at 17:14.
Sennecke scored to move the Ducks back ahead 3-2 at 2:35 of the second period. Dahlin backed off Sennecke as he drove down the left side, giving Sennecke room to cut to the front of the crease for a wrist shot.
Terry scored his first of the game to make it 4-2 at 15:40 when he retrieved the puck along the wall in the Buffalo zone, cut through three Buffalo players on his way to the net and scored with a backhand from the slot.
Anaheim was outshot 9-3 in the second period.
The Sabres cut it to 4-3 at 4:40 of the third period when Jack Quinn scored with a snap shot from the right circle off a rush.
Power tied it 4-4 at 10:05. McLeod won the puck off the face-off at the left dot in the Buffalo zone, with Power putting a snap shot bar down.
Benson buried the backhand dish from Dahlin into a wide open net, putting the Sabres up 5-4 at 11:37.
Mikael Granlund tied it 5-5 with 1:44 left in regulation. Tuch was called for tripping with 2:34 left in the third period, and the Ducks pulled Husso for the extra skater on the two-man advantage. Kreider's pass from below the goal line found Granlund above the right hashmarks for the snap shot that beat Lyon over the glove.