49ers quarterback Alex Smith has had a disappointing start to his career, but he was adamant about one thing -- he wanted to stay in San Francisco.

As a result of his loyalty, Smith was able to rework the final two years of his contract and stay with the 49ers. According to a source, Smith will make $4 million a season in 2009 and 2010, in addition to base salaries that weren't immediately made known.

In his previous contract, he was scheduled to make $24.6 million in the final two years.

"We have reached an agreement with Alex and his agent to keep him as a member of the San Francisco 49ers," general manager Scot McCloughan said in a statement. "Alex expressed a deep interest to remain with the team and that feeling was mutual."

Other teams had shown interest in Smith, who is only 24 years old and has four years of NFL experience. Those teams were willing to pay him more than his 49ers deal, according to a source, but Smith was insistent on making something work in San Francisco.

"I don't measure myself in my contract in terms of what I'm making," said Smith, who missed most of the past two seasons because of shoulder injuries. "Having gone through what I've gone through the last couple of years, and being on the sideline, I guess I've got a different perspective on this game. When it came time to restructure the contract, it wasn't anything to do with ego. I just wanted the chance to compete."

Smith, whose honeymoon in the Maldives delayed negotiations on his new deal, still believes he can live up to the promise that compelled the 49ers to choose him at the top of the notoriously flimsy 2005 draft ahead of Aaron Rodgers, Braylon Edwards, DeMarcus Ware and Shawne Merriman.

Smith reflected Tuesday on his tumultuous times before and after San Francisco made him the No. 1 pick, recalling how he felt swept up in a whirlwind after he led Utah to a perfect record and a Fiesta Bowl victory in the 2004 college season. Coach Urban Meyer's offense turned Smith into a consensus top prospect, and he left the Utes one year early to take advantage.

Although he anticipated the pressure and scrutiny of being a top pick, he was less prepared for abrupt adulthood. Practically overnight, he went from being an economics major sharing a house in Salt Lake City to a multimillionaire with a hilltop home in Silicon Valley and heavy expectations from a long-suffering fan base.

"I'm just much more mature mentally, not to say I was immature," said Smith, who turns 25 in May. "I just think I've grown up a lot. I have a better outlook on it mentally, a better strength. My life outside of football is in a better place."

Smith had 30 starts in his first three seasons, but was placed on injured reserve for the entire 2008 season after he broke a bone in his shoulder, then had more surgery to clean up the shoulder.

His best season may have been in 2006, when he completed 257 of 442 passes for 2,890 yards, with 16 touchdowns and 16 interceptions. Part of his rocky path may be attributed to the 49ers' annual change in offensive coordinators -- Smith has had a new one in each of his four seasons.

John Clayton is a senior NFL writer for ESPN.com. Information from The Associated Press was used in this report.