The hosts had the better of an entertaining first half, with speedy forward Dan James denied by an excellent save from Newcastle goalkeeper Martin Dubravka early on.
Despite continuing in the ascendancy after the break Leeds, without injured striker Patrick Bamford, could not find a breakthrough, and their inability to make the pressure pay proved costly as Shelvey squeezed a 75th-minute free-kick home.
Leeds threw everything at Newcastle late on, but they still could not apply the finishing touch as Marcelo Bielsa's side suffered their first defeat in three league games.
The victory was a crucial one for the visitors, who climbed to 18th in the standings, one point from the safety zone, having played one game fewer than Norwich City in 17th, and seven points behind Leeds in 15th.
"In the last 15 minutes we didn't create enough danger but before their goal, we did more than enough to win the game," Bielsa said.
"We always got to final third with ease but could not pick the final pass, whether from out wide or through the centre. We lacked quality when we needed it."
Chasing their third successive league win, Leeds flew out of the traps in the opening exchanges, roared on by an expectant crowd, and created several early chances.
However, it was Shelvey who went closest to scoring just after the half-hour mark, his excellent volley brilliantly saved by llan Meslier in the home goal.
Rafinha, who was a real menace in the opening period, fizzed one wide on the cusp of half time, before firing another effort across the face of goal soon after the break.
Leeds continued to look the more likely to find a winner, with James unable to hit the target from a good position midway through the second half, but Newcastle still posed a threat on the counter.
Substitute Sean Longstaff drilled just wide as Leeds opened up, before Shelvey broke home hearts as his free kick just crept inside the post, through the hands of the despairing Meslier.
Bielsa shuffled his pack late on but could not prevent Newcastle from picking up their first away league victory of the season at the 10th attempt.
"It is a massive win," Shelvey said. "We knew we had to come and win today as Norwich won last night. Credit to the lads.
"I knew I had to go across goal. I think the keeper gave it a bit of help but a goal is a goal and I'll take it."