Toulouse, who went into the game in top spot but still needed a win to be sure of their place in the next stage of the competition, traded the lead with their opponents on several occasions in a thrilling encounter at the Altrad Stadium.
Lucas and Luke McAlIster traded penalties as the lead swung back and forth, leaving Toulouse with a slender 13-9 half-time lead.
Within minutes of the restart, Toulouse put some distance between themselves and their opponents when Toby Flood charged down another Barard kick and touched down.
However, just 60 seconds later, Lucas Dupont rounded off a swift Montpellier counter to bring the score back to 20-16.
Dupont then grabbed his second try in five minutes, collecting a smart hand off from Paillaugu to put his team 21-20 ahead.
A Flood penalty wrestled the lead back for Toulouse, before Paillaugue struck in response, only for Flood to then kick Toulouse ahead again.
With 12 minutes remaining, Lucas kicked Montpellier in front, and this time Toulouse could not find the score that they needed to go through.
The defeat is Toulouse's first on the road in Europe since January 2013.