The touchdown capped a monster game for Chambers, who set franchise record with 15 catches and 238 receiving yards.
Chambers set up his game-winning touchdown with a 57-yard reception that gave the Dolphins a first down at the Buffalo 16-yard line.
An 8-yard pass to Chambers converted a third-and-3 from the Bills' 9 and Rosenfels spiked the ball on first-and-goal from the 1 before throwing incomplete to Chambers on second down.
Wes Welker appeared to have caught a touchdown pass on third down, but he previously had stepped out of bounds and was flagged for illegal touching. Rosenfels then scrambled for 2 yards on third-and-goal from the 6 and snapped the ball for fourth down with the clock running.
The Dolphins began their comeback early in the fourth quarter when Ricky Williams capped a 70-yard drive with a 5-yard touchdown run.
The deficit was cut to 23-17 the next the Dolphins had the ball as Rosenfels threw a 23-yard touchdown pass to Ronnie Brown.
The Dolphins then stopped Buffalo after the Bills got two first downs, but Rosenfels was intercepted by defensive end Aaron Schobel.
Needing a stop to get another chance, the Dolphins stuffed Buffalo on three running plays to get the ball back with 1:51 left.
Until that fourth quarter, the Dolphins couldn't do much right on offense while their defense was burned by big plays in the first quarter.
Buffalo opened the game with a 46-yard touchdown pass from JP Losman to Lee Evans, and then came right back with a 56-yard score with the same combination after Chambers fumbled on Miami's first possession.
Buffalo made it 21-0 late in the first quarter after a 36-yard punt return by Roscoe Parrish set up a 4-yard touchdown from Losman to Evans again.
The Dolphins tacked on an Olindo Mare field goal late in the first half to go into halftime trailing 21-3.
Buffalo had two big chances to add to their lead in the third quarter, but Channing Crowder recovered a fumble to end one drive and Sam Madison recorded his first interception in over two years to end the other.
That helped set the stage for the Dolphins' comeback, which gave them their first two-game winning streak of the season.