Bath have secured a playoff spot with a one-point victory at Harlequins in a topsy-turvy encounter.
The home side made a fast start and took the lead in the seventh minute, as Nick Evans looped a pass out to the left wing and Ugo Monye crossed the line to score in his last home game before retirement.
However, they were reduced to 14 men just a minute later as Jack Clifford was sent to the sin-bin for collapsing a maul.
Bath took full advantage as George Ford kicked a penalty, before Leroy Houston set up Francois Louw from close range.
Harlequins regained the lead just before half time as a penalty try was awarded for another collapsed maul.
The away side responded shortly after the break through Argentine full-back Horacio Agulla, who cut through the Harlequins defence from deep and touched down under the posts.
Evans kept the Londoners in touch with two accurate penalties, but Houston scored Bath's third try with a close-range finish.
Their joy was short-lived though as Quins turned the ball over and released Monye, and the ex-England winger showed his experience and produced a ruthless finish for his second try of the game.
However, Bath snatched the win in the 76th minute as Ford successfully converted a long-range penalty.