The Magpies gave their survival hopes a major boost with a fourth consecutive game without defeat, while Palace missed a penalty as Alan Pardew's first return to St James' Park ended in disappointment.
© Getty Images
The match got off to a slow start as Palace, who have now won just one of their last 19 Premier League games, looked to break up play and frustrate the home crowd at every available opportunity.
Jason Puncheon sent one mis-hit half-chance wide of the target in the opening 10 minutes before Wayne Hennessey was called into action for the first time, making a routine save to deny Georginio Wijnaldum.
The hosts almost created the first clear chance of the day shortly afterwards when Townsend looked to be clean through on goal, but he was forced too far wide and a good attacking platform went begging.
Pardew's spoiling tactics were successfully winding up the home fans, and the visitors almost piled more misery on those inside St James' Park when Puncheon's reverse pass found Yohan Cabaye, who was only denied from a tight angle by Karl Darlow.
Yannick Bolasie was looking like the most dangerous player on the pitch in the first half, and he tried his luck from a long way out on a counter-attack only to see his powerful effort fly a couple of yards past the post.
Chancel Mbemba tried a long-range strike of his own shortly afterwards having been invited to shoot by the hosts, and his low 35-yard shot needed to be pushed away by Hennessey.
That sparked an improved period for the Magpies, and they had another opening moments later when Moussa Sissoko attacked a cross at the near post, but the midfielder could not get enough on his attempted flick.
The hosts still needed Darlow to keep them level at the other end, though, and the shot-stopper made the standout save of the half with only two minutes remaining when he saw Bolasie's thunderous volley late but still managed to push it away.
© Getty Images
There was one last chance for the home side before the interval, and it was their best one of the entire half as Jack Colback found space inside the area but proceeded to curl his effort wide of the target when he should have done better.
Newcastle came out quicker for the second half, and only an important block from Damien Delaney denied Wijnaldum early in the half after he had engineered space for himself to shoot.
Townsend began to have a growing influence on the game for the home side, testing Hennessey with a long-range effort that was too central to truly trouble the Palace keeper.
© Getty Images
It was Townsend who got the crucial opening goal too, winning a free kick for his side and then taking the set piece himself, curling a 25-yard effort past Hennessey on the keeper's side.
St James' Park erupted as the ball nestled into the back of the net, but the cheer was even louder 20 minutes from time when Darlow made himself a hero by saving Cabaye's penalty.
There was initially shock around the ground when Mike Dean pointed to the spot for a handball against Wijnaldum, but that turned to delight when Darlow threw himself to his left to deny the former Newcastle midfielder.
The tension continued to rise as time ticked by, but the Magpies held out for a crucial victory that takes them one point clear of the drop zone with only two games of their season remaining.