The forward, who turns 37 next week, has played over 500 games since joining his hometown club as a teenager.
"It's what I and the club wanted. I thank them for giving me another chance to wear the shirt of the only team I've ever supported and loved," he said.
Francesco Totti is 47 goals away from becoming Serie A's all-time leading goalscorer. Ex-Lazio, Torino and Juventus striker Silvio Piola, who played between 1929 and 1954, leads the way with 274 strikes.
The ex-Italy international made his Serie A debut aged 16 in March 1993.
Totti has scored 228 goals for Roma, putting him second on the all-time list of leading Serie A goalscorers.
He played a key role in Roma's 2000-01 title win and also helped them to six runners-up spots between 2002 and 2010.
And the five-time Italian Footballer of the Year, whose new deal runs until the end of the 2015-16 season, has started all three matches of Roma's 100% winning start to the Serie A season under new manager Rudi Garcia.
"I have another two years of responsibility and I know that we can do great things here," he said ahead of Sunday's Rome derby against Lazio.
"So far this season we've got off on the right foot, we have a manager who wants his team to play and demands respect, which we haven't had recently."
Totti won 58 international caps for Italy, retiring shortly after helping them win the 2006 World Cup.
Roma captain Francesco Totti has signed a new two-year contract which ties him to the Italian side until just before his 40th birthday.