Hartnell is coming off his best season, scoring a career-high 37 goals. He was second on the Flyers with 67 points.
The deal announced Monday is reportedly worth $28.5 million over six years.
"I'm very happy to be staying in Philly to continue my career playing in front of the best fans in the NHL," Hartnell said.
Hartnell has 222 goals and 252 assists in 11 seasons with Nashville and Philadelphia. He has also recorded 19 goals and 25 assists in 84 career playoff games.