Glamorgan 171 and 171 for 6 (Hemphrey 52*, Labuschagne 51) need a further 383 runs to beat Middlesex 384 and 342 (Robson 140*)
Middlesex set Glamorgan a mammoth target of 556 to win and, after losing six wickets in their second innings, the hosts sill trailed by 383 runs and faced their first defeat of the Championship season going into the final day in Cardiff.
At one stage, Glamorgan were 106 for 1, before their middle order stumbled, yet credit to Charlie Hemphrey who batted resolutely for 66 overs and is unbeaten on 52.
During the morning session Middlesex added a further 153 runs to their overnight score with opener Sam Robson scoring his second century of the season with an unbeaten 140 and becoming the first Middlesex player to carry his bat since Nick Compton in 2006. His first century this summer was also made against Glamorgan at Radlett last month.
Glamorgan's bowlers made early inroads when Rob White was caught behind off Michael Hogan in the second over of the morning then Toby Roland-Jones suffered the same fate off Marchant De Lange in the next over, but Tom Helm and Robson avoided any further alarms by adding 68 for the ninth wicket before Helm gave Marnus Labuschagne a return catch
Tim Murtagh, although not too happy against de Lange's thunderbolts and eventually kept away from the seamer by Robson, tucked into some loose bowing at the other end driving Labuchagne's leg spin for three successive boundaries.
The last-wicket pair put on 76 as the lead stretched beyond 500, and with Dawid Malan showing no inclination to declare as Middlesex batted until 1.10pm before Murtagh skied to long on.
Middlesex had 162 overs left to dismiss Glamorgan and Helm soon struck when Nick Selman was "strangled" down the leg side, flicking at an innocuous delivery that he could easily have left alone. Hemphrey and Labuschagne then settled against Middlesex's predominantly seam attack with Nathan Sowter providing the spin option.
Labuschagne, playing his final game for Glamorgan before joining Australia's squad for the forthcoming practice game against Australia A, has had an outstanding season, and passed 50 for the seventh time in the last eight innings before he was trapped leg before by Roland-Jones. He was also the first player in the country to exceed 1000 championship runs and will surely return to the club next season, availability permitting.
Wickets then fell regularly with another four batsmen adjudged lbw- David Lloyd to Sowter, Billy Root to Roland-Jones, Chris Cooke to Murtagh giving the Middlesex seamer his 800th first class wicket, and Dan Douthwaite who was unlucky to get an unplayable ball that barely got off the ground.