A botched field-goal attempt on Saturday’s opening drive could have set a miserable tone for the 49ers.

Instead, their offense rebounded with a long-sought rhythm, their linebacker crew keyed a defensive surge, and the 49ers’ overall confidence climbed after a 17-3 exhibition win over the Raiders at Candlestick Park.

“I thought it was crisp both by our first units offensively and defensively,” 49ers coach Jim Harbaugh said. “We wanted to see improvement, and that all happened because we had a really good week of practice.”

All that followed a really bad exhibition debut the previous week in New Orleans, where the 49ers endured a 24-3 defeat to the blitz-happy Saints.

“We improved from last week,” quarterback Alex Smith said. “But if we want to be the team we’re talking about being, we need to finish in the red zone, and we can’t turn over the ball. Those first few drives, we didn’t finish.”

The first drive covered 16 plays and reached the Raiders’ 2-yard line, but it ended so poorly, it could have lasting ramifications on punter Andy Lee’s status.

Lee, the holder on placekicks, injured his right hip on a 22-yard field-goal attempt that went askew once he fumbled the snap. He rolled right with the ball and fell hard on his hip after uncorking a desperation pass, which Rolando McClain intercepted.

Lee, a two-time Pro Bowl selection, had to be helped up after subsequent holds on extra-point attempts, and place-kicker David Akers later assumed punt duties. Harbaugh said he doesn’t think Lee’s injury is serious.

The 49ers’ defense is worth taking seriously. After denying Saints quarterback Drew Brees a first down in his three series in the exhibition opener, the 49ers stonewalled the Raiders, whose only points came on a fourth-quarter field goal.

Four-time Pro Bowl selection Patrick Willis shared the spotlight with his fellow linebackers, including his new wingman on the inside, NaVorro Bowman, who had two tackles and pressured Jason Campbell on a third-down incompletion in the Raiders’ first series.

“I saw really great play from the two inside backers — tremendous athleticism,” Harbaugh said. “I marvel at the way they play inside the box but can go sideline to sideline. All the linebackers flashed, too.”

Outside linebackers Parys Haralson and Ahmad Brooks made their presence felt. Haralson chased down Campbell for a fourth-down sack to cap a goal-line stand. Two plays earlier, Willis tracked down Campbell for a 1-yard loss at the 49ers’ 3-yard line.

Brooks continued his breakout preseason by knocking Campbell out of the game with a possible concussion, delivering a jarring hit coming at the end of Justin Smith’s fumble-forcing sack late in the second quarter.

Further aiding the defense’s cause were interceptions by cornerback Tarell Brown and safety Madieu Williams.

Offensively, sturdier blocking, some remarkable catches and highly productive runs made life a lot easier for Smith and his understudy, rookie Colin Kaepernick.

“It started with our offensive line, a reflection of how well the running backs did,” Harbaugh said. “Also, the way they handled the blitz pickup, that was a big improvement from last week, and we saw some of the same blitzes — the edge pressure and safety blitzes — right from the beginning.”

Asked the difference between the last game and Saturday’s, right tackle Anthony Davis said: “We played better.” Asked to elaborate, Davis replied: “We did our job.”

Smith completed 8 of 13 passes for 126 yards and a 61.7 passer rating. He didn’t get sacked, but he did end the second series with an interception by defensive end Matt Shaughnessy. Kaepernick was 6 of 8 for 52 yards with two sacks and a 91.7 rating.

Rookie running back Kendall Hunter had nine carries for 105 yards, including a 53-yard touchdown run 1:31 into the second half for the 49ers’ first touchdown of Harbaugh’s exhibition era.

Frank Gore had four carries for 21 yards on the first series before getting spelled by Hunter, Anthony Dixon and Xavier Omon, whose 5-yard touchdown run with 3:39 remaining capped the scoring.

The catch of the game came from Braylon Edwards, who dived to make a one-handed, sideline grab of Smith’s 32-yard pass at the Raiders’ 22-yard line. That set up a 23-yard field goal from Akers for a 3-0 lead.

For more on the 49ers, see Cam Inman’s Hot Read blog at blogs.mercurynews.com/49ers.