BALTIMORE — The offensive show wasn’t quite as dazzling for quarterback Lamar Jackson and the Baltimore Ravens when they squared off with the rugged defense of the San Francisco 49ers in driving rain at M&T Bank Stadium on Sunday afternoon. But they continued to pile up victories.

Jackson threw for one touchdown and ran for another, Justin Tucker kicked a field goal as time expired, and the Ravens extended their winning streak to eight games by beating the 49ers, 20-17.

“It was a gritty game,” Ravens Coach John Harbaugh said. “I think it was a grit win for us.”

Tucker’s 49-yarder won it for the Ravens after they converted on fourth and one from their own 44-yard line on their winning drive. Harbaugh, once a coach about as buttoned-down as they come, has become an analytics-driven fourth-down gambler with Jackson orchestrating the NFL’s most dynamic offense.

“We knew we were going to go for fourth and one at that point if we got in that situation,” Harbaugh said. “We probably weren’t going longer, maybe. Maybe I would have gone fourth and two. I don’t know. But that was already decided.”

That final gamble by Harbaugh came after the teams had traded failed fourth-down tries earlier in the fourth quarter. The Ravens upped their record to 10-2 and, with the New England Patriots’ loss to the Houston Texans on Sunday night, hold the tiebreaker for the top seed in the AFC playoffs.

Jackson ran for 101 yards but had a modest 105 passing yards on 14-for-23 throwing accuracy. He called the conditions “horrible” for passing and acknowledged that he had gotten frustrated about that.

“It was ticking me off,” Jackson said. “A lot of passes were getting away from me.”

The Niners dropped to 10-2 as they try to stay ahead of the Seattle Seahawks in the NFC West and vie with the Seahawks and New Orleans Saints for the NFC’s No. 1 seed. Both of their losses this season — to the Seahawks in overtime and now to the Ravens — have come on final-play field goals. There is no time for the 49ers to lament this defeat because they play at New Orleans next Sunday.

“We gave ourselves a chance,” cornerback Richard Sherman said. “That’s all you can do. … We just didn’t make enough plays there.”

If this was a Super Bowl preview, the rematch in Miami Gardens, Fla., should be competitive and entertaining. These two teams played a tight and compelling game in difficult conditions Sunday.

“I don’t think about February while we’re in December,” Sherman said. “We’ve got a lot of time, a lot of things to happen, four games to go. We’re going to get ready for New Orleans, and we’ll let the chips fall where they may in February.”

The game’s early going saw the Ravens punt for the first time with Jackson still in a game since Week 9 and trail for the first time since Week 7. They managed to lead 17-14 at halftime after deflecting a 51-yard field goal try by 49ers kicker Robbie Gould as time expired in the first half.

The 49ers struck first on a 33-yard touchdown pass from quarterback Jimmy Garoppolo to wide receiver Deebo Samuel on a fourth-and-two play. Samuel outmaneuvered Ravens cornerback Marcus Peters on what amounted to a jump ball. The Ravens got even by converting a fumble lost by Garoppolo on a sack into a touchdown pass from Jackson to tight end Mark Andrews.

In the second quarter, the Ravens sandwiched a touchdown run by Jackson and a field goal by Tucker around a 49ers’ touchdown on a 40-yard dash by running back Raheem Mostert. Sherman said the Baltimore offense was “about the same” as the 49ers expected. He praised the play of Jackson, a top league MVP contender.

“He’s a good decision-maker,” Sherman said. “He knows his angles. He knows his leverage. He knows when to get down. He knows when to stay up. He knows when to cut back, when to bounce outside. He knows when to keep it. He doesn’t take more than the defense will give him. He doesn’t waste time taking shots or looking downfield when it’s not there. He’ll check it down and take what the defense gives him. So it’s cool. He played a good game.”

The Niners tied the game at 17 on a third-quarter field goal by Gould. Earlier in the quarter, 49ers safety Marcell Harris made a spectacular defensive play by taking the football from Jackson’s hands at the end of a run. But it all came down to a kick by the ultrareliable Tucker, something the Ravens will take every time.

“The conditions were not great,” Tucker said. “But being able to come through for this team in that moment is really special.”

Said Harbaugh: “You wouldn’t rather have anybody else in that situation. That field, that wind, that rain, all that stuff that was going on there — that’s the guy you want in that situation. I’m very grateful that we have him on Thanksgiving weekend.”

Read more: