Karl Hawley netted the only goal of the game 17 minutes in at Sixfields, with the visitors having plenty of chances to earn at least a point.
The on-loan striker popped up in the first half to net the only goal of the game to earn the Cobblers a welcome home victory.
"Sometimes you have to win ugly and this was an extremely ugly win," said Gray.
"Even though we were the home side we had to play mainly on the counter and full credit goes to Hartlepool for that.
"They're a very good side and I can't believe we've kept a clean sheet against them to be honest.
"We did the right thing in both boxes and people will look in the paper and see that Northampton have won 1-0."
The Pools manager Danny Wilson could not believe that his side had left Sixfields on the end of a 1-0 defeat.
Wilson's side created numerous chances but were unable to reply to Hawley's strike.
"You have to get something for all your hard work and we didn't get that," he said.
"I'm sure from their point of view they'll be very, very relieved that they've come away with a 1-0 win.
"I don't think they'll be able to believe it, but unfortunately that's been the story of us."