Earlier, Ben Foden's unconverted try seemed to have secured a drawfor Northampton who also had Dominic Waldouckand George Pisi on the scoresheet.
Josh Strauss and Nikola Matawalu had crossed for Glasgow and Townsend, whose side are currently second in the RaboDirect PRO12 standings, believes they can take heart from their performance.
"I'm absolutely delighted, these are rare moments when you get a last-minute try and win, there is a great buzz in the team," said Townsend.
"The players played with a lot of passion. They went out for the win and played some very good rugby.
"Peter also really deserved his try, he is a very committed player. The two hand-offs and his pace were quality, but what I'm most proud of is the support line he ran.
"There is frustration but I believe we will become a better team in the league and next season in Europe from the lessons we've learned.
"It hasn't been the season we wanted in the Heineken Cup, but we have been very competitive both home and away."