Maritimo picked up their first Europa League win of the campaign with a 2-1 victory over Club Brugge at the Estadio dos Barreiros.
The Portuguese side headed into the tie at the foot of of Group D but victory over Georges Leekens' side ensured it was their Belgian opponents who finished bottom.
Nuno Goncalo Abreu put Maritimo in front but Lior Rafaelov levelled from the spot with a little over five minutes remaining before a Ramos Heldon header won the game two minutes later.
It was the visitors who created the first opportunity, when after five minutes, Bjorn Vleminckx was played in by Birger Verstraete, but he shot straight at Romain Salin from 12 yards out, with the keeper able to make a comfortable catch.
The visitors were made to pay for not making the most of their early dominance as Maritimo took the lead in the 18th minute. Miguel Luis Olim's outswinging corner was headed home by Nuno Goncalo Abreu.
Determined to not end their tournament on a low note, Brugge came out strongly in the second period and Vleminckx forced a decent save from Salin just a minute after the restart.
Then the drama unfolded in what was a frantic last five minutes. First, Nuno Briguel was penalised for handball in the 86th minute, with the spot kick converted by Rafaelov.
However, any hopes Brugge had of getting a draw were quickly dashed as Heldon headed home Branco Igor Rossi`s cross to seal the win.