Totti, playing his final game for Roma after a 25-year career that garnered only one league title, was handed a final-day gift when he was called upon to replace Egyptian Mohamed Salah on 54 minutes.
But for the 40-year-old playmaker, and the thousands of fans who showed up to pay tribute to 'Il Re di Roma' (The King of Rome), it was a nervy final game of the Serie A season.
Genoa travelled to the capital intent on ruining Totti's farewell party and stunned the stadium into silence when Pietro Pellegri hit their opener after just three minutes.
Roma hit back with goals from Edin Dzeko and Daniele De Rossi having them 2-1 ahead, only for Darko Lazovic to level 11 minutes from time.
With Napoli romping to a comfortable 4-2 win away to Sampdoria, Roma were in trouble, on their way to a third-place finish and without an automatic place in the group stages of next season's Champions League.
But moments after Totti saw a chance thwarted by the boot of Santiago Gentiletti, Perotti fired the hosts into a 3-2 lead when he got on the end of Dzeko's knock-down to beat Eugenio Lamanna from close range on 90 minutes.
Roma's 28th win of the campaign left Luciano Spalletti's men in second place, one point ahead of Napoli and four behind champions Juventus, who sealed a record sixth consecutive Serie A title last week.
Totti said after the game: "The moment has arrived. I've cried the whole day. This was my only jersey.
"I took this decision with my wife and my family. I'd like to stay for another 25 years. Thank you Roma, thanks to my family, my Mum, Dad and brother.
"I'd love to write a poem, a song, but all I can do is try to use my feet to express myself."