MILAN - Diego Perotti struck at the death as Roma handed club icon Francesco Totti a farewell to remember with a thrilling 3-2 win at home to Genoa in a packed Stadio Olimpico on Sunday.

Totti, playing his final game with the capital side after a storied 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. Totti failed to score on what was his 619th and final Serie A appearance of 785 in total.

But by the end of a valuable win that secured Roma's place in next season's Champions League, the evergreen playmaker experienced a send-off that saw the entire stadium shed tears, and one teary-eyed fan break the barriers to run and hug his hero, as they waved off argualy the most symbolic player in Italy over the past 20 years.

"The moment has arrived. I've cried the whole day. This was my only jersey," said Totti. "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 use my feet to express myself."

Totti played a pivotal role in Roma ending an 18-year wait for the scudetto in 2001, and -- barring any last-minute decision to continue his playing career elsewhere -- is now set to start working alongside Roma's sporting director Monchi. He added: "Damn it. I get get goosebumps when I think about June 17, 2001. From tomorrow, I'll be a grown up."

Yet for Totti, and the thousands of fans who showed up sporting special T-shirts and banners to pay tribute to 'Il Re di Roma' (The King of Rome), it was a nervy final game of the 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.

De Rossi paid tribute to his close friend Totti and his status as a symbol of Rome, as well as Roma, over the years: "He won the scudetto, and he united a city that falls apart at the least problem. "But Totti is now a friend that I won't get to see every day."

Napoli finished third as Dries Mertens missed out on Serie A's 'Capocannoniere' top scorer's award. He got the opener away to Sampdoria, with Lorenzo Insigne, Marek Hamsik and Jose Callejon also scoring. The Belgian finished on 28 goals, one shy of Dzeko's tally of 29. Torino's Andrea Belotti, on 25, will need five goals if he is to overtake Dzeko late Sunday when his side host Sassuolo.

Crotone, one point from safety, will battle for top-flight survival later at home to Lazio, with Empoli, fourth from bottom, away to already relegated Palermo.