Toulouse passed up the chance to finish top of Pool 4 in the European Cup after squandering a 20-9 lead in their 27-26 defeat at Montpellier.
The visitors appeared in a comfortable position after Toby Flood's converted try increased their lead to 11 points at the beginning of the second half.
But Montpellier came roaring back and two tries from Lucas Dupont kick-started their recovery before they sealed victory by the smallest of margins to give them their only win in the group.
Toulouse's slip-up meant Bath finished top of the pool following their victory over Glasgow.
It was Montpellier who started well as two penalties from Ben Lucas and one from Benoit Paillaugue put them 9-0 ahead just after the half-hour.
Clement Poitrenaud's converted try narrowed the gap to two points before Toulouse claimed the lead for the first time thanks to Luke McAlister's penalty.
The New Zealand fly-half added another three points shortly before the hooter while it appeared the visitors were well on their way to victory when Flood crossed the whitewash three minutes after the resumption.
But Dupont touched down twice in the space of five minutes soon after, first reducing arrears with a converted try in the 46th minute before his next score gave Montpellier a one-point lead.
Flood put Toulouse back in front with a penalty and did so again after Paillaugue had found the posts.
But it would be the hosts who had the last laugh as Ben Lucas slotted home his third penalty in the 68th minute - and they held out for an unlikely victory.