The Cobblers, who are 16th in League Two, have suffered a disappointing start to the season after being relegated last term.
Chairman David Cordoza told the club's website: "It is with a heavy heart that we have come to this decision.
"It is necessary to consider the best interests of the club, long term and to try and win promotion this season."
Northampton have won just two of their first six games, collecting seven points.
And Cordoza added: "We, the board of directors, gave Stuart every opportunity to strengthen this summer and to build a squad capable of taking the club straight back up.
"Although Stuart brought some good players to the club our results and performances have been very disappointing.
"We enjoyed some very good times under Stuart. Sixteen months ago he took us to one of our highest placings in the last 40 years."
Gray had been in charge of the Cobblers since January 2007, when he replaced John Gorman, and finished a respectable 14th in League One.
The following season he did even better lifting the Cobblers to ninth in the table.
Cordoza added that the club are not in a rush to appoint a new boss.
"We will not put any timescales on this. It is important we take our time to get the right man," he said.
"There will be plenty of speculation as to who the new manager might or might not be. As a club we won't be commenting on that."