The fullback was set to become a free agent in 2015. The seventh-round pick in 2011 is expected to be among the highest-paid fullbacks in the league.
Miller is a big part of the 49ers' offense. He is a standout as a blocker, receiver and on short yardage. Quarterback Colin Kaepernick called the Central Florida product the team's "Swiss Army Knife" last season.
"Bruce is a hard-working, dedicated young player that has done an outstanding job for us, both on and off the field," 49ers general manager Trent Baalke said in a statement. "He is one of those players that contributes a lot more to the team and to the community than he gets credit for, yet wouldn't have it any other way. We are pleased that Bruce has chosen to extend his stay with the 49ers."
Miller, who is popular in the locker room and among the team's fan base, broke his scapula in Week 15 and was put on the injured reserve. The team didn't run well down the stretch and in the playoffs without Miller.
Getting Miller signed shrinks the team's 2015 priority list that includes Kaepernick, Michael Crabtree and guard Mike Iupati. Like Miller, cornerback Chris Culliver is also a candidate to have his contract extended a year early this offseason.