Ramsay rounded off a flowing team move in the 90th minute as the hosts completed a comeback from a goal down and ended North Korea's qualifying campaign.
The visitors had been expected to easily beat the Philippines as they seek to return to the World Cup, after appearances in 1966 and 44 years later at South Africa in 2010.
But they let a place in the next round, as well as a berth at the 2019 Asian Cup, slip through their fingers as they failed to go through as one of the four best-performing group runners-up.
"If we had at least gotten a draw today we would still have been hopeful to qualify for the next stage. But we did not and I think there's hardly a hope of going to the final stage," North Korean coach Kim Chang Bok told reporters immediately after the game.
"The problem was, in the first half we lost two absolute chances of scoring and I think that became the turning point," he added.
Misagh Bahadoran put the Philippines in front in the 43rd minute, heading into an empty net after North Korean keeper and captain Ri Myong-Guk parried Javier Patino's stinging shot with his right foot.
The Koreans had been the better team until then, hitting a post and having another shot cleared off the line.
And the visitors were level in first-half injury time as So Kyong-Jin smashed home after the Philippine defence could only half-clear the midfielder's initial shot.
Within seconds of the restart North Korea were ahead after a free kick caused panic in the Philippine goalmouth, presenting midfielder Ri Hyok-Chol with a simple tap-in.
But the Philippines rallied and midfielder Manuel Ott levelled in the 84th minute.
And as the seconds ticked down, a sweet move highlighted by a back-heeled assist from forward Miguel Tanton put Ramsay through for the raucously celebrated winner.