McAvoy returned from a six-game suspension he received for slashing Buffalo Sabres forward Zach Benson during Game 6 of the Eastern Conference First Round last season.
Fraser Minten scored twice for the Bruins (5-2-0), who have won three straight. Matthew Poitras and Pavel Zacha also scored, Morgan Geekie had two assists, and Jeremy Swayman made 35 saves.
Macklin Celebrini and Ivar Stenberg each had a goal and an assist for the Sharks (3-3-0), who have lost two straight and three of four. Yaroslav Askarov made 20 saves.
Minten put the Bruins up 1-0 at 12:55 of the first period. Casey Mittelstadt got his own rebound behind the net and passed up to Minten, who skated in off the bench and beat Askarov over his blocker with a shot from above the right circle.
Jacob Trouba tied the game 1-1 at 15:29. He one-timed a pass from Kiefer Sherwood past Swayman's blocker two seconds after a power play expired.
McAvoy put the Bruins back ahead 2-1 at 18:43. JJ Peterka found a loose puck to the right of Askarov and passed to McAvoy, who tapped it past Askarov's left pad as he was crashing the net.
Stenberg tied the game 2-2 with a power-play goal at 5:48 of the second period. Celebrini waited in the right face-off circle before finding Stenberg at the back post for a tap-in past Swayman's right leg.
It was the first career goal for Stenberg, who was the No. 2 pick in the 2026 NHL Draft.
Poitras gave the Bruins a 3-2 lead at 8:42. Mark Kastelic had the puck poked off his stick behind the Sharks' net, but it popped out to the left post, where Poitras jammed it past Askarov, who was looking the other way.
Zacha pushed the lead to 4-2 with three seconds left in the period. While skating in on a 2-on-1 rush, Morgan Geekie found Zacha in the left slot for a wrist shot that beat Askarov's blocker.
Celebrini scored a power-play goal at 5:04 of the third period to cut it to 4-3. Will Smith fed a pass to Stenberg down the left wing, and he sent it back across the ice to Celebrini at the right face-off dot for a one-timer.
Minten scored his second goal of the game to make it 5-3 at 11:47. Sharks defenseman Luca Cagnoni blocked a pass on a rush that went right to Marat Khusnutdinov, who found Minten at the top of the crease for the tap-in past Askarov's right pad.
Will Borgen banked the puck off the right boards from his own zone for an empty-net goal at 18:18 for the 6-3 final.