The one-year contract is worth $2.75 million, and Boldin will have a chance to make an additional $1.25 million in incentives, a source told ESPN's Adam Schefter.
He met with the Bills in Orchard Park, New York, last week and had agreed to a deal then, only to back out before reaching agreement on Monday, the source said.
Boldin, 36, is one of the most prolific receivers in NFL history and someday is expected to be a candidate for Hall of Fame enshrinement.
He is 14th in NFL history in receiving yards with 13,779 -- needing just 120 yards to move past Cris Carter into 13th -- and is second to Larry Fitzgerald (14,389) among active players. He is ninth in NFL history in receptions (1,076) and third among active players behind Fitzgerald (1,125) and Jason Witten (1,089). He's two catches behind Terrell Owens for No. 8 all time.
Boldin's 82 career receiving touchdowns are tied for 23rd with Brandon Marshall and Reggie Wayne, and he's tied with Marshall for third among active players behind Antonio Gates (111) and Fitzgerald (104).
Boldin struggled to get separation from defenders last season, but he continued to be reliable, catching 67 passes for 584 yards and a team-high eight touchdowns for the Lions.
Playing for Arizona, Baltimore, San Francisco and Detroit, he has had seven 1,000-yard seasons -- most recently in 2014, when he had 1,062 yards for the 49ers -- and is a three-time Pro Bowl selection.
Boldin is also well-known for his work off the field. He was named the NFL's Walter Payton Man of the Year following the 2015 season and was one of five NFL players to meet with lawmakers in Washington in November to discuss race relations and police brutality in the United States.
ESPN's Michael Rothstein contributed to this report.