The San Francisco 49ers weren’t able to trade for quarterback Aaron Rodgers just before the NFL draft in April.

And they couldn’t beat him Sunday night.

Six days after Rodgers and the Green Bay Packers silenced the “trolls,” as Rodgers put it, they showed Sunday that they remain firmly among the NFC’s upper tier of contenders. Rodgers was sharp and he was clutch. And the Packers beat the 49ers, 30-28, in dramatic fashion at Levi’s Stadium in Santa Clara, Calif.

“Those are the types of situations that we’re made for,” Packers wide receiver Davante Adams said. “And we went out there and took care of another one.”

Kicker Mason Crosby’s 51-yard field goal as time expired won it for the Packers. Rodgers maneuvered the Packers rapidly into position for Crosby’s kick after the 49ers took a 28-27 lead on quarterback Jimmy Garoppolo’s 12-yard touchdown pass to fullback Kyle Juszczyk with 37 seconds remaining.

“They beat us up twice in ’19,” Rodgers said. “Those were tough ones. The road trip out West from Green Bay is always tough. But it feels a lot better when you’re going back [after] a win.”

The Packers won their second straight game since a lopsided season-opening defeat to the New Orleans Saints in Jacksonville, Fla., that raised so many questions following the offseason melodrama in which Rodgers was the central figure. This triumph was far more impressive than last Monday’s victory over the Detroit Lions at Lambeau Field, as the Packers went on the road and handed the 49ers their first loss of the season following a 2-0 start.

“It gives some legitimacy to some of the things we’ve been talking about,” Rodgers said in his postgame news conference, “that that [opening game] was kind of an aberration and that we are a talented football team. It felt like in the locker room today that we finally had the energy that I’d been waiting to see…. It felt like it was such a growth moment for us. I’m really happy for the guys to feel that. It feels like okay, now we’re on our way. Now we can get into this. Now we know how to win and we can get this thing moving in the right direction.”

Rodgers completed 23 of 33 passes for 261 yards. He threw touchdown passes to Adams and fellow wideout Marquez Valdes-Scantling. Tailback Aaron Jones also had a touchdown run, and Crosby kicked three field goals.

“It’s a good feeling no matter what point it is in the season, for sure,” Adams said.

It was a homecoming for Rodgers, who was born in Chico, Calif., and played in college at Cal. The 49ers, once among the teams to famously pass over Rodgers when he entered the league, inquired with the Packers about the possibility of trading for Rodgers around the time of the NFL draft this year.

That came amid the offseason saga surrounding Rodgers, and the 49ers were quickly rebuffed. That trade inquiry reportedly created a bit of a strain in the relationship between Packers Coach Matt LaFleur and his former close coaching associate, Niners Coach Kyle Shanahan.

“I would say earlier in my career there was maybe a different motivation that involved April 23, 2005,” Rodgers said. “That kind of adjusted over the years to just a love for this area, a lot of respect and appreciation for my time here…. I love the area, still have a lot of friends in the area. It’s always fun coming back. It hadn’t been fun two of the previous three. But this one’s pretty sweet.”

The Packers led 17-0 in the second quarter before the 49ers rallied. Rookie quarterback Trey Lance entered the game and scored on a one-yard touchdown run as time expired in the first half. Garoppolo reentered and threw a touchdown pass to wide receiver Brandon Aiyuk on the opening possession of the third quarter.

Running back Trey Sermon’s touchdown dive got the 49ers within 24-21 in the fourth quarter. Garoppolo lost a fumble, leading to a Packers field goal, to set up the furious final sequence. Garoppolo was good in crunch time. Rodgers was better.

“No timeouts from the 25[-yard line], you need two chunk throws,” Rodgers said. “I knew that. So that’s why it wasn’t dink and dunk. We didn’t have any time for that. We had to get at least 15 [yards] on the first play.”

Adams was back in the game after being examined earlier in the medical tent on the Packers’ sideline following a hit by 49ers safety Jimmie Ward. Adams said he was examined for a possible concussion. But he actually had absorbed the hit in his chest, he said, and he initially was having trouble catching his breath.

The first play of the Packers’ final drive was a 25-yard completion from Rodgers to Adams on a play, Rodgers said, that had been drawn up during Thursday’s practice and then was suggested by LaFleur on the sideline. Rodgers spiked the ball to stop clock. Then came an incompletion, a 17-yard strike to Adams and another spike to halt the clock with three seconds left and bring on Crosby.

“What a game,” LaFleur said. “That’s one I will never forget.”

Said Adams: “I was thinking it’s a lot of time on the clock to count us out…. We’ve got the quarterback to do it. We’ve got all the personnel to do it, to go make plays like that.”

Read on for live action from Sunday night’s game.