The contract will carry a value of $650,000 next season and $800,000 in the 2019-20 season.
Harpur, 23, has one point in 20 NHL games with Ottawa this season. The Niagara-on-the-Lake, Ont., native also has two goals and seven assists in 16 American Hockey League games with the Belleville Senators.
"Ben has continued on his developmental path this season, improving his game to the point where we project him to be a significant contributor to our team for years to come," said Senators general manager Pierre Dorion.
Harpur was selected by Ottawa in the fourth round (108th overall) of the 2013 draft. He played in 31 career NHL regular-season games and nine playoff games for the Senators last season.