Terms weren't disclosed, but reports in the Bay Area speculated that the contract will make Lee the highest-paid punter in the NFL, or close to it. The Oakland Raiders' Shane Lechler, whose base salary will be $3.8 million in 2012, currently holds that distinction.
Lee's current contract was set to expire after the 2012 season.
"The 49ers are pleased to have reached a long-term contract extension with Andy," general manager Trent Baalke said in a statement. "Andy has established himself as one of the top players in the game at his position. He is a valued member of our organization and community. As we stated earlier this year, it is our objective to keep the core of this team together long term, and this is just another step in that direction."
He set NFL single-season records since at least 1976 for gross (50.9 yards) and net (44.0) punting averages last season. His 59.6-yard gross average at home against Seattle last season was the third-highest for a game since at least 1976, the first year such stats were tracked officially (minimum four punts). He had a 54.2-yard net average in the game, which is the second-highest in the NFL since at least 1976.
The 29-year-old Lee has been selected to the Pro Bowl three times in his career and has also been named to three All-Pro teams. He has played in 128 games for the 49ers and holds team records in punts (723), yards (33,069), gross average (45.7), net average (38.9) and punts downed inside the 20-yard line (209).
Since 2007, Lee's gross punting average (47.9) and net average (40.7) rank second in the NFL.
Information from ESPN.com NFC West blogger Mike Sando and The Associated Press was used in this report.