Ulster dominated the first period at Scotstoun and could have had a lead greater than the 15-7 advantage they enjoyed, which came largely thanks to Darren Cave's score and a penalty try.
Finn Russell's penalty and Tommy Seymour's seventh try of the Guinness PRO12 campaign after the break gave Glasgow a narrow lead but Paddy Jackson's spectacular score - and some granite-like late defence - meant the visitors left as 22-17 victors.
It was just a second league defeat at Scotstoun for the Warriors since November 2013 but Townsend couldn't fault his players after the way they responded to a difficult first 40 minutes.
"As coaches, we're very proud of the effort that went into that second half," said Townsend.
"We had a few injuries and had to adapt, as well as having a couple of players suffering from illness.
"Pat MacArthur had to call off just before the game, whilst Jonny Gray played the full game despite being ill.
"We were second best in the first half, and maybe we didn't adapt as well to the early injuries to Tjiuee [Uanivi] and Greg [Peterson] as we should have.
"They kept getting front foot ball, and I thought Ruan Pienaar was outstanding. We defended much better in the second half and scored a cracking try.
"We had a few more sequences close to their line, but credit to Ulster's defence for holding out."