Matthew Stafford threw for 366 yards and two touchdowns and Matt Gay’s 30-yard field goal as time expired lifted the Los Angeles Rams to a 30-27 divisional playoff victory over Tom Brady and the defending Super Bowl champion Tampa Bay Buccaneers on Sunday.

Brady rallied the Bucs from a 27-3 second-half deficit with help from three Los Angeles turnovers, tying the game on Leonard Fournette’s 9-yard run on fourth-and-inches with 42 seconds remaining. But the seven-time NFL champion didn’t get an opportunity to finish the job.

Stafford led the Rams downfield after the ensuing kickoff, using completions of 20 and 44 yards to league receiving leader Cooper Kupp to set up Gay’s winning field goal.

Los Angeles Rams quarterback Matthew Stafford (9) celebrates with wide receiver Cooper Kupp (10) after his reception against the Tampa Bay Buccaneers during the second half of an NFL divisional round playoff football game Sunday, Jan. 23, 2022, in Tampa, Fla. (AP PhotoJason Behnken)

Los Angeles Rams quarterback Matthew Stafford (9) celebrates with wide receiver Cooper Kupp (10) after his reception against the Tampa Bay Buccaneers during the second half of an NFL divisional round playoff football game Sunday, Jan. 23, 2022, in Tampa, Fla. (AP PhotoJason Behnken)

Stafford, who had never won a postseason game before beating Arizona in the previous week’s wild-card round, completed 28 of 38 passes without an interception. The 13-year veteran also scored on a 1-yard run as the Rams (14-5) advanced to next Sunday’s NFC championship game at home against the San Francisco 49ers.

Brady completed 30 of 54 passes for 329 yards, one touchdown and one interception. He was sacked three times and lost a fumble.

The Bucs (14-5), who lost to the Rams for the third time in two seasons, were trying to become the first team to repeat as Super Bowl champions since the Brady-led New England Patriots during the 2004 season.

Los Angeles Rams outside linebacker Von Miller (40) celebrates after the team defeatdd the Tampa Bay Buccaneers during an NFL divisional round playoff football game Sunday, Jan. 23, 2022, in Tampa, Fla. (AP PhotoJason Behnken)

Los Angeles Rams outside linebacker Von Miller (40) celebrates after the team defeatdd the Tampa Bay Buccaneers during an NFL divisional round playoff football game Sunday, Jan. 23, 2022, in Tampa, Fla. (AP PhotoJason Behnken)

More AP NFL: https://apnews.com/hub/nfl and https://apnews.com/hub/pro-32 and https://twitter.com/AP_NFL

Los Angeles Rams kicker Matt Gay (8) celebrates as he leaves the field after the team defeated the Tampa Bay Buccaneers during an NFL divisional round playoff football game Sunday, Jan. 23, 2022, in Tampa, Fla. (AP PhotoJason Behnken)

Los Angeles Rams kicker Matt Gay (8) celebrates as he leaves the field after the team defeated the Tampa Bay Buccaneers during an NFL divisional round playoff football game Sunday, Jan. 23, 2022, in Tampa, Fla. (AP PhotoJason Behnken)