The formerSouth Carolinastandout announced his decision in a statement posted on Twitter.
Lattimore, 23, spent the 2013 season on the non-football injury list and remained on that list this season. However, he began practicing last week with the hope that he would be able to play later this season.
The 5-foot-11, 220-pound back suffered serious knee injuries in 2011 (ACL and MCL tears in his left knee) and 2012 (right knee) during his time at South Carolina.
"This was a very difficult decision for Marcus and it was clear after speaking with him that he had put a lot of thought into it," 49ers general manager Trent Baalke said in a statement. "He is a high-character young man who has done everything asked of him and more during his time with us and we have a great deal of respect for the strength and commitment he showed throughout the rehab process.
"It has been a pleasure to have Marcus as a member of our team and our community and we are confident that he will be very successful in whichever path he chooses to take in life. We look forward to supporting Marcus and wish him nothing but the best."
Lattimore said he will return to South Carolina, where he majored in public health, to complete his degree. South Carolina football coach Steve Spurrier said Lattimore will always have a place at the university.
Spurrier said he, athletic director Ray Tanner or university president Harris Pastides could find a position for Lattimore after football. The coach says Lattimore was among South Carolina's most popular and well-respected players ever.
Lattimore has a tax-free $1.7 million insurance policy that he should be able to collect on, his agent, Michael Perrett, told ESPN.com on Monday.
Lattimore took out the permanent total disability policy during his junior year at South Carolina, which sources say cost him in between $10,000 and $15,000.
Lattimore's injury resulted in him falling from a consensus first-round pick to a fourth-round selection by the 49ers in the 2013 draft, a projected monetary loss of at least $5 million in signing bonuses and guaranteed salary.
The standard permanent total disability policy of an athlete who buys the policy in college allows for that athlete to play a rehab period of up to four games the following year in college or in the pros. Once the player plays in four games, the policy is considered expired.
Lattimore played in no games since his injury two years ago.In order to collect on the $1.7 million, Lattimore would have to file a claim and to have a doctor physically rule him unable to play.
ESPN NFL Insider Adam Caplan, ESPN.com's Darren Rovell and The Associated Press contributed to this report.
Marcus Lattimore Intends To Retire
The "NFL Insiders" crew reacts to the news that 49ers running back Marcus Lattimore has decided to retire.
Gore Confident 49ers Will Hit The Playoffs
ESPN 49ers reporter Paul Gutierrez discusses running back Frank Gore's confidence that the 4-4 49ers will make the playoffs this season.