The team made the announcement Monday. Smith is the third member of the 49ers' defense to retire this offseason, along with inside linebackers Patrick Willis and Chris Borland.
Smith said his troublesome left shoulder was not responding.
"If you don't have the tools, you can't do that job," he said. "It's time to go.
"When you're on bald tires, you're on bald tires ... it's a young man's game. It was just time for me to move on.
"It was a great ride."
The 49ers had been planning for Smith's retirement the past several offseasons -- they have drafted 10 defensive linemen since 2011, including this year's first-rounder, Arik Armstead -- and gave Smith as long as he needed to make his decision.
"Tough. Physical. Durable. Hard-working. Dedicated. Selfless. Justin embodies each of those qualities and brought even more with him to work each and every day," 49ers CEO Jed York said in a statement. "Whether it was chasing down a wide receiver and forcing a fumble to seal a win, or driving a tackle back into the quarterback's chest, he gave everything he had every play. Justin has earned the respect of the entire NFL community and he will always be remembered as one of the 49ers all-time greats."
Smith, who turns 36 on Sept. 30, was the No. 4 overall selection of the 2001 draft out of Missouri, and after seven seasons with the Cincinnati Bengals he came to the Niners as a high-profile free-agent signing in 2008.
It was also with the 49ers where he joined Jim Tomsula, the team's defensive line coach since 2007. And under Tomsula, Smith was selected to five straight Pro Bowls, from 2009 through 2013.
But injuries began to slow Smith in recent years. A partially torn left triceps limited him at the end of the 2012 season -- he missed two games, the first time since his rookie season he had missed a game -- and a back issue slowed him in the second half of last season.
Still, Smith started strong last year as his three sacks led the Niners at midseason and his 23 tackles at the time were the most for a Niners lineman.
"Last year, he was playing with half an arm," then-Niners defensive coordinator Vic Fangio said at the time. "This year, he's playing with a healthy body ... I actually see a better player than last year because of the health. And I'm sure he's down a decibel or two from where he was in 2011, but not very much.
"It would be a shame if he did retire for all of us because he's still playing at a very high level. I expect him to make the Pro Bowl again, and expect you guys to lead the charge five years when he's done playing to get him up in Canton."
Smith's midweek practice reps were watched closely and the back became more of an issue. Because after averaging 42.9 snaps through the 49ers' first 11 games, Smith averaged 36.8 snaps in their last five games, per ESPN Stats & Info.
And he had only two sacks in the second half of the season, while finishing with a career-low 43 tackles and just five sacks, the third-lowest total of his career, even as they were tied for the second most on the team with Dan Skuta, but behind the six sacks of Ahmad Brooks and Aaron Lynch.
Smith was labeled as having an "average" season in a joint ESPN.com/Pro Football Focus project at the end of this past season.