Maritimo score in the final minutes to win 4-3 at Vitoria de Guimaraes with both sides being reduced to 10 men in the second half.
Alex Soares put the visitors in front after a cross from Moussa Marega found him alone in the box and the winger simply tapped into an open goal to break the deadlock.
Vitoria pulled level late in the half in scrappy fashion after a cross was sat up to the back post for Ricardo Valente to pull out a tidy finish to equalise for the home side.
However, Maritimo went back in front just before the break as Soares returned the favour, allowing Marega to score and give them the lead heading into half time.
Maritimo went further ahead in the second half as Edgar Costa received the ball just outside the box and fired a curling effort beyond the reach of Douglas Jesus.
The hosts would pull a goal back moments later though as Cafu was put through on goal and the Brazilian fired a fierce strike into the Maritimo goal.
Vitoria completed the comeback from the penalty spot after Romain Salin picked up a straight red for a foul in the area and Otavio stepped up to make it 3-3.
The hosts were then reduced to 10 men as well after Henrique Dourado was sent off for a second bookable offence with 15 minutes to go.
In the final minute, it would be Maritimo that would steal the three points through Fransergio after a one-two with Tiago Rodrigues saw the Brazilian through on goal and he powered it home.
The victory moves Maritimo up to eighth in the Primeira Liga table, while Vitoria drop to 10th.