Tom Brady has agreed to a three-year, $27 million contract extension with the Patriots, a deal that will keep him with New England through the 2017 season, a league source confirmed to ESPNBoston.com's Mike Reiss.

The extension includes a $3 million signing bonus along with annual salaries of $7 million in 2015, $8 million in 2016 and $9 million in 2017, when Brady will turn 40, according to the source.

Brady's relatively modest deal frees up $15 million worth of salary-cap space for the Patriots in the 2013 and 2014 seasons, a league source told ESPN.

Though other quarterbacks recently have signed deals nearly twice as lucrative, Brady has made it clear he wants to play until he's 40 and finish his career with the Patriots, whom he led to Super Bowl wins for the 2001, 2003 and 2004 seasons, and losses in the big game after the 2007 and 2011 seasons. Monday's extension should help New England maintain a competitive team around the two-time NFL MVP.

The Patriots gained $8 million in salary-cap space this year and $7 million in cap room next season. Brady's cap numbers, which were scheduled to be $21.8 million in each of the next two offseasons, now will be $14.8 million this season and $13.8 million next season.

Brady and the Patriots started discussing the extension about a month ago, according to a league source. Brady was willing to accept this deal, the source said, because of the trust that exists between the two-time Super Bowl MVP and the team.