SANTA CLARA, Calif.—Alex Smith had perhaps the best start-to-finish game of his career against the Bills.

It was the first time he threw for 300 or more yards in a winning effort, and he came within two points of a perfect 158.3 passer rating.

He had help.

For the first time this season, Smith wasn’t sacked as the offensive line, particularly right tackle Anthony Davis and right guard Alex Boone, neutralized Mario Williams and the Buffalo pass rush. The 49ers also had a very strong rushing performance led by Frank Gore’s 106-yard effort. A week after rolling up 245 yards against the Jets, the 49ers had 311 yards on the ground against the Bills.

Smith and the 49ers always talk about having a balanced offense. On Sunday, that balance was nearly perfect: 310 yards through the air, 311 on the ground.

NOTES: Smith injured the middle finger of his throwing hand midway through the fourth quarter when he was hit by Williams. Smith appeared to hurt the digit as he braced himself upon hitting the ground. The quarterback had X-rays, and the injury was diagnosed as a sprain. Smith said it was no big deal, and he played two more snaps after the injury occurred. However, he did not make another throw the rest of the afternoon as he was then taken out of the game, presumably because the 49ers were so far ahead. A finger sprain on the throwing hand of the starting quarterback will bear monitoring during the week.