SANTA CLARA, Calif. — Tom Brady chatted up one of his old 49ers favorites in Tom Rathman, then pushed aside all that nostalgia for a few hours to earn his 199th career victory.

Brady threw for 280 yards and four touchdowns, and the New England Patriots beat San Francisco 30-17 on Sunday. Brady tied Hall of Famer Brett Favre for the second-most wins by a quarterback in NFL history. With his next win, Brady will match Peyton Manning for the top spot.

Back home in the Bay Area playing on San Francisco's home field for the first time, facing the team he cheered as a boy, Brady handled the game and took care of the ball on a day it was difficult to do so.

When the game ended, a rainbow had emerged over the entire stadium — a fitting cap to Brady's fine afternoon. No. 12 then threw a football into the stands behind one end zone and hustled off to see all of his supporters.

"It was very cool. It doesn't get any better than that. To have the first chance to ever do that was very special," Brady said . "I felt it in pregame warmup and it carried right to the last play of the game. It was pretty great.

"They have a great organization, they always have. They inspired a lot of kids here in the Bay Area in my time growing up, and I was one of them."

Under pressure on the slick grass, Brady found Danny Amendola for a 5-yard touchdown to start the fourth quarter, then later hit Malcolm Mitchell on a 56-yard score for his fourth TD pass.

Brady also threw short touchdown passes to Julian Edelman and James White on his first two possessions and completed 24 of 40 passes. The AFC East-leading Patriots (8-2) bounced back from last week's loss to the Seahawks on a rainy day at Levi's Stadium.

Edelman caught a 4-yard TD pass for the first score of the game , breaking away from Keith Reaser to the corner and barely keeping two feet inbounds. Edelman finished with eight receptions for 77 yards, and Mitchell had four catches for 98 yards.

Brady hit White for a 9-yard touchdown , then Amendola reached a career high with his fourth TD catch of 2016 on the first play of the fourth quarter. Mitchell's athletic, reaching grab between two defenders and straightaway speed after the catch resulted in his first career touchdown to seal it.

Brady completed eight of his first nine passes and nine of 11, while New England's defense flew through a leaky offensive line at Colin Kaepernick for four first-half sacks and five in all.

Brady had never played a road game against the 49ers. He injured his knee before the Patriots' 2008 visit to Candlestick Park — the very place the young Brady used to cheer Joe Montana and witnessed "The Catch" by Dwight Clark.

It only took until his 17th NFL season for Brady to finally get this chance. Of course, he shined in the big moment.

"He's Tom Brady. He's going to make the plays he's going to make, and that's what he did today," 49ers linebacker Ahmad Brooks said.

LeGarrette Blount had a season-long 44-yard run and finished with 124 yards rushing.

Kaepernick threw an 18-yard touchdown pass to Vance McDonald late in the first half to get the 49ers (1-9) within 13-10, but they didn't do enough right after intermission until Shaun Draughn's late 13-yard TD catch.

Levi's Stadium was so packed with Patriots fans it almost sounded like Foxborough.

Kaepernick has looked improved each week since regaining the starting job last month, completing 16 of 30 passes for 206 yards. But the 1-and-Niners — as their nickname quickly became Sunday — lost a ninth straight game under first-year coach Chip Kelly since opening the season with a shutout of the Rams.

SO MANY TARGETS: During the regular season, Brady has thrown touchdown passes to 63 players — second-most behind Vinny Testaverde's 70.

Brady also had four TD passes with no interceptions for the 21st time in his career.

PATS PASS RUSH: Five Patriots had sacks on Kaepernick: Patrick Chung, Malcolm Butler, Kyle Van Noy, Dont'a Hightower and Rob Ninkovich.

"He's a tough guy to tackle," coach Bill Belichick said. "Our players stayed after him."

LEWIS' DEBUT: Pats running back Dion Lewis made his season debut after recovering from reconstructive surgery on his left knee. He had a 9-yard reception for a first down during New England's opening drive.

DAWSON'S MARK: With a 33-yard field goal in the first quarter, San Francisco's 41-year-old kicker, Phil Dawson, became the 10th kicker in NFL history to reach 400 field goals.

SMITH'S FIRST MISS: San Francisco wideout Torrey Smith missed his first career game and had his streak of consecutive games snapped at 89 because of a shoulder injury sustained last week at Arizona. This is his sixth NFL season.

UP NEXT

Patriots: at Jets on Sunday.

49ers: at Dolphins on Sunday.