The Welsh region led 16-11 at half-time after two tries from Scotland winger Nikki Walker and two penalties from Dan Biggar. Richie Gray crossed for the hosts with Ruaridh Jackson adding two penalties.
But the Warriors stepped it up after the break as Richie Vernon and Kevin Tkachuk claimed tries to give them breathing space, before Walker completed his hat-trick late on as the Ospreys narrowly missed out on a losing bonus point.
It looked as though Glasgow were going to be on the wrong end of a serious hammering in the early stages as nothing went right for the home side from sloppy handling to poor tackling.
Biggar had the Ospreys on the scoreboard after a Glasgow handling move had gone askew, and three minutes later came the opening try as Jerry Collins and Lee Byrne put Walker through and he shrugged off Rob Dewey's challenge on the way to the line.
The Ospreys were on top in every department and when Biggar missed a long range penalty, it seemed only a matter of time before they increased their lead.
But the visitors were dealt a blow when full-back Byrne departed with a hand injury that puts his involvement in Wales' autumn Tests in doubt.
On the quarter-hour mark, Jackson slotted a penalty for Glasgow which brought them to life.
Biggar landed his second penalty but by now the home side were contesting the breakdown and were giving as good as they got.
Their first try arrived when Colin Gregor popped the ball up to lock Gray who took off over the 22 and sold an outrageous dummy to score.
Just when it looked as though Glasgow were going to take control, the simplest of defensive errors saw Tommy Bowe find Biggar on a run around which baffled the home defence and the efforts of Gregor and Jackson could not prevent Walker claiming his second try.
With three minutes of the half left, Dougie Hall was pulled down inches short and Gray and Moray Low were held up before Ryan Jones collected a yellow card for a professional foul.
Jackson duly kicked the resulting penalty and Glasgow went in 16-11 adrift, ruing some basic errors.
Into the second half it was the Ospreys who looked uncomfortable and Glasgow's confidence grew after a sparkling handling move which almost saw Alastair Muldowney over in the corner, but Jackson landed another penalty to reduce the margin to two points.
Biggar had the chance to stretch the Ospreys lead but his missed kick was one of the few mistakes the young fly-half made as he controlled a game in which more experienced heads around him were in panic.
Jackson missed the chance to give Glasgow the lead after a great run by Vernon but a couple of minutes later his replacement Duncan Weir banged over the kick which took the home side ahead for the first time.
It was all Glasgow now with the Ospreys' defence looking increasingly vulnerable. When Barclay pinched the ball from the base of a creaking Ospreys scrum, he almost made the line. But nothing was going to stop Vernon crashing over off Gregor's pass.
Weir converted, Glasgow kept a stranglehold on the last 10 minutes and when replacement Ed Kalman combined with Tkachuk for his fellow prop to score it slammed the door on the Ospreys, although Walker did go over for his hat-trick try in the closing minutes.
|Glasgow Warriors Score Card|
|Ospreys Score Card|