SANTA CLARA, Calif. — The most improbable, unbelievable throw by San Francisco 49ers quarterback Alex Smith didn’t even hit its intended target.

It came last Saturday before Game 1 of the National League division series between the San Francisco Giants and Cincinnati Reds, when Smith had the honor of throwing out the first pitch.

Who could have guessed that Smith, once the Bay Area’s most derided athlete, would get those raucous cheers as he walked out to the mound? This was a guy who went from the NFL’s No. 1 pick, to a struggling starter, to a backup, to nearly being cast aside by the franchise that had rushed him onto the field.

Now, as a leader of the hottest team in football and owner of a league-best 108.7 passer rating, he’s embraced by a fan base that once roundly rejected him.

So it was really no big deal that he threw that ceremonial pitch into the dirt in front of home plate, even though he joked: “I’m disgusted with myself.”

No matter, no one questions his accuracy anymore, not with him competing 68.6% of his passes with eight touchdowns and only one interception. Smith, whose team will play host to the New York Giants on Sunday in a rematch of last season’s NFC championship game, has thoroughly reinvented himself.

And he has done it in a unique way. Unlike quarterbacks such as Jim Plunkett, Steve Young and Rich Gannon, who had career breakthroughs after changing teams, Smith has been able to survive the worst of times with the 49ers — times when coaches have flat given up on him — to emerge on the other side.

Coach Jim Harbaugh has played an essential role in the transformation, casting his lot with Smith from the start, something previous coaches Mike Nolan and Mike Singletary didn’t do.

“Can’t tell you how much respect I have for him,” Harbaugh said. “That he has played well, handles himself, does all the things. [I] kind of look back and say, ‘Man, I wish I would have done as good a job as he has done.’ On and off the field, in everything that he does and his approach to the game, I think it’s a real example.”

That confidence paid off last season when Smith — who had cycled through a constant carousel of different offensive coordinators and quarterback coaches — clicked with Harbaugh and offensive coordinator Greg Roman. They put their faith in Smith and he delivered, with 17 touchdowns and just five interceptions, helping carry the club to within one win of the Super Bowl.

There’s no magic to the emergence of Smith. He has a better head coach — a former NFL quarterback who had his own ups and downs; better personnel around him on both sides of the ball; is healthier after undergoing several shoulder surgeries, and is simply older and more experienced. It’s easy to forget that Smith is only 28, younger even than Brandon Weeden, Cleveland’s rookie quarterback.

In the darkest times, could Smith have envisioned being in the position the 49ers are now in, as an elite team with him at the helm?

“I was certainly playing for it. I wasn’t playing to continue to lose,” he said, standing at his locker this week. “You continue to put the work in and to fight and play because you’re trying to win games. No question, thought it could get better, didn’t know when or how.”

Smith, in his seventh season, is one of just two No. 1 picks in the modern era to spend more than five seasons with his original team despite never making a Pro Bowl. The other is defensive end Kenneth Sims, the top pick in 1982, who played eight seasons with New England.

The 49ers have stood by Smith, even though they came close to tossing him aside several times.

Nolan pressed him into action with a bad supporting cast almost immediately, then got frustrated with him for not developing quickly enough. The coach publicly questioned his toughness, wondering why he wouldn’t play through a separated shoulder that would require several surgeries.

Singletary never trusted Smith’s ability to throw, and instead ran a simple, run-oriented offense. He once referred to Smith as “meek,” a comment that wasn’t malicious but was less than a ringing endorsement of the quarterback’s leadership skills.

Said Jed York, 49ers chief executive, of Smith: “We had to look at it and say, ‘We have somebody here that knows the team, knows the offense, knows the system. We just haven’t done a good enough job of putting him in a stable situation where he can be successful.’ A lot of that are failures I would put on the organization, not Alex.”

Harbaugh was hired in January 2011, a few months before the lockout. He soon announced that Smith was his quarterback, even though there was widespread speculation that the 49ers might sign Matt Hasselbeck. Then came the lockout, and that helped Smith in at least two significant ways:

First, with no free-agency period (until one ultimately came in late July), the 49ers couldn’t sign another veteran quarterback, even if they wanted to, and no other teams could make a play for Smith.

More important, Smith was among the few 49ers who had Harbaugh’s playbook — he got a copy during the brief lifting of the lockout — so he was able to conduct “Camp Alex” at San Jose State, run through the plays with his teammates, and show his ability to lead. He paid for players to come to the camp, and even loaned them his car when necessary. The team bonded.

That confidence in Smith grew throughout last season, as the team went from 6-10 in 2010 to 13-3. After the offense ground to a halt in the conference title game against the Giants — when 49ers receivers totaled one catch for four yards — San Francisco invested in its receiving corps, including adding free agents Mario Manningham and Randy Moss.

The 49ers looked at Peyton Manning this off-season, although Harbaugh insists they only were evaluating him and were determined to stick with Smith. Regardless, because of the way Smith played last season, the bar would have been set much higher for Manning in San Francisco than it was replacing Tim Tebow in Denver.

San Francisco almost blew it with Smith. Scot McCloughan, general manager of the 49ers when they drafted Smith, was warned in 2005 by friend and quarterback guru Mike Holmgren to take it slow with Smith, not to rush him onto the field. But the 49ers did.

“I told Scot, ‘There will be a learning curve for him. You know it. I know it. But the owner has to know it. The media has to know it. Everybody has to know it,’” Holmgren recalled in an interview with The Times in 2011.

Instead, Smith was the starter by Week 5, and in his debut had four interceptions, was sacked five times and posted an 8.5 passer rating. The 49ers would finish last in the league in passing yards for the first time in club history.

“He was destined to fail,” Holmgren said.

For Smith, that seems like three careers ago. He’s not Young or Joe Montana, but he’s a seasoned leader of a 4-1 team that rolled up a franchise-record 621 yards of offense last Sunday and has beaten its last two opponents — the Jets and Bills — by a combined 79-3.

He’s a quarterback who can open the NLDS with a fastball in the dirt and still get a standing ovation.

“He’s stuck with it and persevered when a lot of other guys would have quit,” York said.

“You can argue about who’s the best quarterback in the National Football League. Well, I think Alex Smith is the toughest, and that fits our football team better than anything else.”

sam.farmer@latimes.com

twitter.com/LATimesfarmer