PSG looked on course for a dream result when first-half goals by Ezequiel Lavezzi and Javier Pastore put Carlo Ancelotti's men in the driving seat.
But their hopes of reaching the quarter-finals suffered a setback in the space of two wild minutes at the end of the contest.
First Rami stole in behind the defence to reduce the arrears before PSG striker Zlatan Ibrahimovic was sent off for aiming a stamp at Andres Guardado.
Of Ibrahimovic's red card, PSG coach Carlo Ancelotti said: "He was out on the wing, he made a tackle and he did not deserve to be sent off.
"But I suppose that is football."