Roma remained in the hunt for a place in the Champions League next season with a dramatic win over Bari, despite ending the game with only nine men and missing a penalty.
Simone Bentivoglio put the home team in front with the first of three penalties in the 25th minute.
Francesco Totti levelled after half an hour, but Erik Huseklepp gave a spirited Bari the lead again just before the break.
Daniele De Rossi, Kamil Glik and Simone Perrotta were all given their marching orders in the second half, in which Totti brought Roma level from the spot in the 57th minute before missing his hat-trick with a penalty 20 minutes later.
Bari hit the woodwork twice before Aleandro Rosi scored a fortunate winner for the Giallorossi in the fifth minute of stoppage time to take them to within a point of the top four.
The first penalty of the game was awarded in the 24th minute when Huseklepp's cross hit Juan's hand inside the six-yard box.
Bentivoglio stepped up and sent the spot kick straight down the middle with Doni diving to his right.
Totti replied five minutes later with a free-kick which caught Jean-Francois Gillet out as it curled around the wall, which the Bari goalkeeper had clearly not lined up well enough to cover his right-hand post.
Jeremy Menez should have put Roma ahead after exchanging passes with Totti in the 37th minute, but he seemed to stumble as he shot and the ball went wide.
Despite already being relegated to Serie B, Bari were not offering any gifts to Roma and they went ahead again in the 42nd minute with Huseklepp's first goal in Italian football.
The Norwegian headed Jaime Romero's cross into the far corner from seven yards out.
Roma's hopes of launching a recovery were dealt a blow early in the second half when a rush of blood to the head saw De Rossi sent off for elbowing Bentivoglio in the face in the 48th minute.
But Roma seemed to play even better with 10 men and Totti again tested Gillet with a free-kick, but the Belgian goalkeeper dived to make a save.
The second penalty of the game was given in Roma's favour when Juan had his short tugged by Parisi, and Totti struck a perfect spot-kick in off the base of the left-hand post with Gillet unable to reach it, despite guessing the right way.
A minute later, a dangerous cross from Romero was deflected by Juan onto the inside of the far post and the ball fell back into the arms of a relieved Doni.
Roma were given the chance to win the game with the third penalty which heralded the second red card, for Glik, in the 77th minute.
However, Totti's precision was not so good this time as he aimed for the same corner, but a combination of Gillet's fingertips and the post denied him.
Abdelkader Ghezzal hit the crossbar as Bari threatened to steal a win in the last minute, but it was Roma who took all three points deep in stoppage time, shortly after Perrotta saw red for punching Andrea Masiello in his back.
Rosi did not know too much about it either as David Pizarro's cross bounced against his midriff and into the goal from a few yards out.