In his first full season in the NHL, the 23-year-old emerged as a top pairing defenseman -- along with fellow restricted free agent Ivan Provorov.
"We are very pleased with the progress Travis has made in his young career," Flyers general manager Chuck Fletcher said in a statement. "He is a skilled, two-way defenseman with excellent size and mobility. He is a big part of our present and our future."
Sanheim had nine goals and 26 assists, to go along with a minus-4 and 49.5 Corsi percentage. He blocked 133 shots last season.
The Flyers already took a step to bolster their blue line with a trade for veteran Justin Braun from the Sharks.
"I'm obviously really excited. It's a big step in my career," Sanheim said in a statement. "I'm looking forward to another two years with the Flyers. I'm really excited with the way the team's moving forward and the moves we've made this summer."