SANTA CLARA, Calif. — The San Francisco 49ers gave away everything but the game.

Jimmy Garoppolo threw a 5-yard touchdown pass to Dante Pettis with 1:15 remaining and the 49ers overcame five turnovers to beat the Pittsburgh Steelers 24-20 on Sunday for their first 3-0 start in 21 years.

"It's never perfect," cornerback Richard Sherman said. "We didn't play perfect today but our record is perfect."

The Niners gave the ball away four times in the first half and then lost a fumble again in the fourth quarter, but still managed to pull out the victory and spoil Mason Rudolph's first career start in place of the injured Ben Roethlisberger for the Steelers (0-3).

A team that won just 10 games combined in coach Kyle Shanahan's first two seasons heads into a week off in good shape after surviving the home opener.

"It's a good start," Garoppolo said. "There's a lot of football left. Three wins won't get you anything in this league."

Rudolph threw two long touchdown passes in the second half, connecting on a 76-yarder to JuJu Smith-Schuster and a 39-yarder to Diontae Johnson that gave the Steelers a 20-17 lead in the fourth quarter.

The Niners answered the first strike with a 75-yard touchdown drive capped by a 4-yard run by Jeff Wilson Jr. and appeared poised to do the same when they drove inside the 10 following the second score.

But on third down from the 7, a shotgun snap hit receiver Richie James Jr. as he went in motion and T.J. Watt recovered the fumble for Pittsburgh on San Francisco's third red-zone turnover of the game.

The Steelers then gave it right back when James Conner was stripped by Arik Armstead and DeForest Buckner recovered at the 24. After a third-down holding penalty on Mark Barron extended the drive, Garoppolo found Pettis for the go-ahead score.

Pettis had caught just four passes for 22 yards this season before the TD grab, but made the biggest play yet for San Francisco.

"There obviously have been a lot of ups and downs," he said. "You're not just going to be good every single day. Now that I know what it's like to go through that, I know I can do this. I know I'm here for a reason."

Pittsburgh was unable to generate a first down on the ensuing drive with Rudolph taking a sack on third down and throwing an incompletion on fourth to send the Steelers to their second 0-3 start since 2000.

"We get ready for next week," coach Mike Tomlin said. "It's as simple as that. That's life in the National Football League. It'd be the same had we won. We're not into the keep it together discussions. That's not how we're built."

Garoppolo finished 22 for 32 for 277 yards. He threw two interceptions on the first three drives on passes that hit his receivers' hands and also lost a fumble on a bad snap from center by Weston Richburg with the Niners inside the Pittsburgh 10.

Rudolph finished 14 for 27 for 174 yards, throwing an interception to K'Waun Williams on the opening drive of the second half to set up Wilson's first touchdown.

INJURIES

Steelers: TE Vance McDonald left the game in the first half with a shoulder injury.

49ers: CB Ahkello Witherspoon left in the second half with a foot injury that he doesn't believe is serious.

IMPRESSIVE DEBUT

Steelers safety Minkah Fitzpatrick made a big impact in his first game since being acquired from Miami this past week in a deal that sent a first-round pick to the Dolphins. He intercepted a pass in the first quarter and then forced a fumble by Raheem Mostert in the red zone in the second quarter that Devin Bush recovered. He became the first Steelers player with an interception and forced fumble in the opening half since James Harrison did it against the Chargers on Nov. 16, 2008.

ROUGH DEBUT

Cornerback Jason Verrett made his debut for the 49ers and was picked on after Witherspoon left with the injury. He committed a 32-yard pass interference penalty and then was beaten deep by Johnson on a 39-yard score the following play to give the Steelers a 20-17 lead in the fourth quarter.

MISSED OPPORTUNITIES

The first two turnovers by San Francisco gave the Steelers the ball in scoring position but they were unable to generate a first down on either drive and settled for field goals. Rudolph completed three passes for only 5 yards the first possession, leading to a 46-yard field goal by Chris Boswell. Rudolph then threw an incomplete pass on third-and-5 following two runs by James Conner, leading to a 26-yard field goal.

UP NEXT

Steelers: Host Cincinnati on Monday night.

49ers: After a week off, the Niners host Cleveland on Oct. 7.

Five takeaways not enough for Steelers in Rudolph's 1st start

SANTA CLARA, Calif. — Mason Rudolph delivered two big plays in his first career start in place of the injured Ben Roethlisberger.

Rudolph and the rest of the Pittsburgh Steelers' offense couldn't do much of anything outside of those two long touchdowns and ended up losing a game the San Francisco 49ers kept trying to hand them.

James Conner lost a fumble with Pittsburgh protecting a lead late in the fourth quarter and the Steelers' opportunistic defense couldn't come up with a key late stop in a 24-20 loss on Sunday that sent the team to its second 0-3 start since 2000.

"A lot of mistakes," Rudolph said. "We can't be that slow-starting in the first half. I have to give our team and our defense more of a chance to put some points up early and get ahead with all of the turnovers they created. They played unbelievable. They did everything coach asked them through the week in creating turnovers and flying around. We have to back them up."

The Steelers' offense couldn't do enough. Pittsburgh settled for field goals after getting a pair of interceptions deep in San Francisco territory in the first quarter.

The offense then couldn't do much of anything outside of Rudolph's two deep strikes: a 76-yarder to JuJu Smith-Schuster in the third quarter that gave the Steelers a 13-10 lead, and a 39-yarder to rookie Diontae Johnson that made it 20-17 in the fourth.

Pittsburgh gained 126 yards the rest of the game, averaging just 2.6 yards per play to drop a third straight to open the season.

Rudolph finished 14 for 27 for 174 yards with an interception that set up San Francisco's first touchdown.

"For a young guy to come and start his first game in an away game on the West Coast and going against a great team, I think he handled himself well," Smith-Schuster said. "There were situations where we messed up, didn't execute or turned the ball over, he stayed positive and kept us going."

Despite all that went wrong on offense, the Steelers were still in position to win after the Niners committed their fifth turnover of the game — and third in the red zone — on a botched snap that gave Pittsburgh the ball with a three-point lead and 6:49 left to play.

But instead of burning the clock and backing up the 49ers, Conner lost a fumble on the third play of the drive, giving the 49ers the ball at the Pittsburgh 24.

The Steelers looked like they made the stop when they forced an incompletion on third-and-11 from the 14, but Mark Barron was called for a holding penalty.

"I just felt like the guy ran into me," he said. "I just absorbed him. I didn't get my hands off him fast enough and that was the call."

Two plays later, Jimmy Garoppolo found Dante Pettis for a 5-yard score with 1:15 to play and the Steelers were on their way to their first loss in 38 years when generating five takeaways.

But Pittsburgh turned those gifts into six points, while the Niners got 14 after two giveaways by the Steelers.

"We turned the ball over twice. They scored two touchdowns in the second half and really that's the difference in the game," coach Mike Tomlin said. "In the first half, we were getting turnovers and we were settling for field goals. So that's the story line of the game, if you will. Such is life in the National Football League. We take responsibility for it. We own it. Not good enough today. We won't blink."

The Steelers now must rebound and try to salvage the season with Roethlisberger out the rest of the way with an elbow injury.