Newcastle United suffer agonising defeat as Liverpool keep their title hopes alive
Rafa Benitez's side twice came from behind at St James's Park thanks to goals from Christian Atsu and Salomon Rondon.
But substitute Divock Origi claimed all three points for the visitors with a late header.
Liverpool now lead second-placed Manchester City by two points, though Pep Guardiola's side have a game in hand.
Newcastle fans again showed their appreciation for manager Rafa Benitez, out of contract in the summer, during the game, which has left the club 14th in the league ahead of next weekend's season-ending fixture against Fulham.
Wor Flags also unveiled a stunning surfer flag in the Gallowgate End of the stadium before the match.
Benitez, United's manager, had made two changes, replacing Jonjo Shelvey and Federico Fernandez with Ki Sung-yueng and Jamaal Lascelles respectively.
Virgil van Dijk opened the scoring in what was to be a breathless first half at St James's Park.
The defender, unmarked, headed a corner from Trent Alexandar-Arnold past Martin Dubravka. It was a terrible goal for a team which has prided itself on its defensive discipline to concede.
But Liverpool, having taken the lead, seemed to relax, and Newcastle took advantage.
The ball was clipped to Matt Ritchie to the left of the visiting box, and he played a low ball across the box to Rondon, whose shot was handled on the line by Alexandar-Arnold.
Atsu, however, was there to net the rebound.
United were behind again in the 28th minute. A clever backheel from Daniel Sturridge allowed Alexandar-Arnold to cross for Mohamed Salah, who squeezed the ball between Dubravka and the left-hand post.
Again, it was too easy for Liverpool, who took their one-goal advantage into the break.
Newcastle made a businesslike start to the second half, though their visitors were a threat whenever they got into the final third of the pitch.
Rondon forced a save from Alisson with a low shot, but the goalkeeper couldn't stop his next effort. Liverpool failed to fully clear a corner from Ki Sung-yueng, and the ball was headed back into the box, where Rondon was waiting.
The striker, stood to the left of goal, let it bounce before firing a fierce shot across Alisson and into the far corner of the net.
Liverpool then lost Salah to a head injury after the striker collided with Dubravka.
And Origi – who replaced Salah – headed a free-kick from fellow substitute Xherdan Shaqiri past Dubravka with four minutes left on the clock.
Liverpool held on to take the title race into the final weekend of the season.
Newcastle's players went on a lap of appreciation after the game.
NEWCASTLE UNITED: Dubravka; Manquillo, Schar (Muto, 90), Lascelles, Dummett, Ritchie; Perez, Ki, Hayden, Atsu; Rondon. Subs not used: Darlow, Barreca, Fernandez, Kenedy, Shelvey, Diame.
LIVERPOOL: Alisson, Alexander-Arnold, Lovren (Milner, 83), van Dijk, Robertson, Henderson, Fabinho, Wijnaldum (Shaqiri, 66), Salah (Origi, 73), Sturridge, Mane. Subs not used: Mignolet, Gomez, Oxlade-Chamberlain, Matip.
Goals: Van Dijk 13, Atsu 20, Salah 28, Rondon 54
Bookings: Schar 46
Referee: Andre Marriner (West Midlands)