The deal was announced Sunday by general manager Don Sweeney.
The 21-year-old McAvoy emerged as one of the top defencemen on the Eastern Conference championship team last year. Playing alongside Zdeno Chara on the No. 1 pairing, he had even more ice time than the longtime iron man, an average of 22 minutes, 10 seconds per game.
McAvoy had seven goals and 21 assists in 54 regular-season games and two goals and six assists in the post-season, when he averaged 24:30 on ice.
A first-round draft pick in 2016, McAvoy was first called up for the 2016-17 playoffs.