SANTA CLARA — Prior to Jimmy Garoppolo’s pass to Kendrick Bourne late in the fourth quarter to convert on third-and-16, the 49ers had failed on 50 straight attempts, according to the Associated Press.

But Garoppolo didn’t convert third-and-16 just once. He did it two times, consecutively, helping the 49ers beat Rams 34-31 at Levi's Stadium. After Bourne’s reception, Raheem Mostert ran the ball for 1 yard and then Garoppolo was sacked by Rams linebacker Samson Ebukam on the ensuing play.

Faced with a third-and-16 situation again, Garoppolo took the snap from shotgun and fired a deep pass to Emmanuel Sanders for 46 yards

After the completion to Sanders, Tevin Coleman shortened the winning field goal attempt for kicker Robbie Gould with a 9-yard run to the right side. Garoppolo knelt down for one play to center the ball in the middle of the field to give his kicker the best possible angle.

For the fourth game in a row, the final score of the 49ers' game was decided by a play in the final seconds, Thankfully for the home team, this time, it was in their favor. Shanahan left the game impressed by Garoppolo’s ability to stay cool under pressure.

"He was resilient,” Shanahan said. “Third-and-16's aren’t the best situations to be in. I’m usually not feeling great in those situations and those guys gave him enough time in protection to make the first one to Bourne over the middle. Had a similar play up the middle, the safeties got real wide and got the opportunity to Emmanuel down the field.”

Third-and-long situations are not loved by coaches and Shanahan is no different. He admitted having and disliking that part of his play sheet.

“We do and it’s not a fun area, until today,” Shanahan said with a slight smile. “It went well, usually I get in I-formation and run the ball out of frustration, but that would have been bad in that situation so I’m glad I didn’t.”

The 49ers on Saturday became only the second team in the past 40 years to convert multiple third- or fourth-down attempts of 15 yards or more on a game-winning drive, according to the Elias Sports Bureau.

Prior to the final two third-down conversions, the 49ers had only been successful two other times out of eight attempts Saturday. When told about failing on the previous 50 third-and-16 attempts, Shanahan was not shocked.

“No, it wouldn’t surprise me at all,” Shanahan said. “Usually it’s such a low percentage that you don’t really try on third-and-16 much. Usually you just try to survive the down and get half of it and punt. But, we were in a situation that we didn’t have that and I think we struggled on third down most of the day. Just have to get in longer distances, I guess.”

[RELATED: 49ers beat Rams for Beathard family]

It was not a stellar day for Garoppolo, who performed most effectively on the the final drive. After the first drive in the fourth quarter the 49ers quarterback had only completed 10 of his 19 attempts for 114 yards, two interceptions and a 31.4 rating. Apparently he thrives under the pressure of third-and-16 scenarios.

“It’s the exact situation we were looking for,” Garoppolo said with a laugh. “To convert two of those the way we did, it was pretty incredible."