AS Roma beat Parma 2-1 at the Stadio Olimpico on Sunday to end the season in sixth place in Serie A as captain Daniele De Rossi made his final appearance for the club.
However, the home side's slim chances of Champions League qualification ended as Inter Milan, Atalanta and AC Milan recorded wins to finish above them.
Roma's decision not to offer De Rossi a new contract was met with furious protests from the fans, but a capacity crowd said an emotional farewell to their second-highest appearance holder as he pulled on the red and yellow shirt for 616th and final time.
Claudio Ranieri, taking charge of Roma for the last time as caretaker manager, knew that his side needed everything to go their way to climb into the top four but they had to settle for sixth instead, earning them a place in the Europa League second qualifying round next season.
Roma finished with 66 points, three adrift of fourth-placed Inter.
The home side went in front when a botched clearance fell into the path of Pellegrini on the edge of the area and his volleyed finish took a deflection on its way in.
De Rossi was substituted inside the final 10 minutes to a standing ovation as he bowed out 18 years after his senior debut for the club. Only Francesco Totti has made more appearances for Roma, with 786, than the former Italy international.
Parma had not read the script, though, as former Roma winger Gervinho struck a low finish past goalkeeper Antonio Mirante to draw the visitors level with four minutes remaining.
The home side's response was almost immediate, as Perotti got on the end of a cross from substitute Cengiz Under to head in the winner from close range.
The stadium remained full for a long time after the final whistle as De Rossi embarked on a lap of honour with his family and team mates to salute the tearful supporters.