Shafer spent the 2016 season out of football after going 14-23 in three years as Syracuse's coach.
Before taking over at Syracuse, Shafer was the Orange's defensive coordinator from 2009-12. He also has been a defensive coordinator at Northern Illinois, Western Michigan, Stanford and Michigan.
Shafer said Friday in a release announcing the hire that "we will put a physical, attacking, multiple defense on the field that will excel in fundamentals and tackling."
Shafer replaces Tyrone Nix, who was fired Dec. 28 after five seasons as Middle Tennessee's defensive coordinator.
Middle Tennessee went 8-5 this season, including a 52-35 Hawaii Bowl loss to Hawaii.