Fulham and City had spurned chance after chance - including Anelka from two yards - before the Frenchman collected Shaun Wright-Phillips' pass in his stride and blasted past Maik Taylor in the 83rd minute.
Taylor and Peter Schmeichel had both been in imperious form - and when they were beaten, their defenders raced back to clear off the line.
Schmeichel denied Fulham an early lead in a stop-start first half with an excellent one-on-one save from Steve Marlet.
It needed a much more dramatic intervention to prevent the Frenchman scoring after 38 minutes.
Marlet beat the big Dane but right-back Richard Dunne raced back to clear off his own goalline.
Fulham had their own defensive hero as well, with Martin Djetou heading clear after Ali Benarbia's shot was parried by Taylor - who also denied Anelka from close range.
The second period was thrilling stuff, with Ali Benarbia clearing off his line and Anelka making his astonishing miss before hitting the winner for ex-Fulham boss Kevin Keegan.
England boss Sven-Goran Eriksson was in the directors' box Loftus Road to assess the home talent on show. He saw Benarbia and Darren Huckerby start for the first time in two and three months respectively.
Wright-Phillips and Shaun Goater were both dropped from the team that beat Aston Villa 3-1 on Boxing Day. Taylor was in goal for Fulham again in place of Edwin van der Sar, sidelined with a broken metatarsal bone in his right foot.
Steed Malbranque's run-and-shot was the first moment of excitement, although his effort drifted wide of Schmeichel's goal.
Anelka hit back for the visitors and sent a deflected drive skidding just past the post. After eight minutes, Huckerby let fly with a thumping volley after Fulham half-cleared a corner - but Steve Finnan charged his shot down.
Eyal Berkovic forced Taylor into action for the first time with a 20-yard attempt. The Fulham keeper dived to his left and saved well.
But the game exploded in the 19th minute when Sean Davis came within a whisker of scoring a quite brilliant goal.
He linked up with Malbranque and sent a scorching left-foot volley just wide from 20 yards. Marlet had a much clearer-cut scoring opportunity 30 seconds later, racing onto Sava's through-ball but shooting straight at Schmeichel.
Malbranque, Fulham's liveliest player, had his follow-up strike blocked. Huckerby outwitted Zat Knight and poked the ball to Anelka, whose shot was met by the onrushing Taylor.
The game had moved up several gears now - and it took dramatic goalline clearances at either end to keep the scoreline blank.
Seven minutes before the break, Malbranque squared for Marlet, 10 yards out.
Schmeichel got a piece of his shot, but the ball was spinning goalwards until Dunne raced back to clear.
And at the other end, Taylor parried Benarbia's powerful free-kick and recovered to palm the ball up in the air. Djetou climbed tallest to head over for a corner.
Two minutes after the interval, a woeful piece of control by Djetou almost led to the opener for City. Huckerby seized possession and raced goalwards to send as hot whistling into the side-netting.
And the striker should have done much better minutes later when he raced onto Benarbia's header and got round Taylor thanks to a lucky deflection.
But his ball back into the danger zone was sliced horrendously.
Schmeichel also saved from Marlet as both sides pushed for the breakthrough.
Schmeichel's bravery denied Fulham twice in three minutes at the hour mark.
First, he threw himself at Marlet's close-range shot to block - and then he seized the ball on his goalline as Sava and Djetou slid in.
And as Keegan's men hit back, a trademark Huckerby run ended with a shot which flew wide. It was end-to-end stuff at the moment - with Benarbia clearing Marlet's header off his line and Fulham substitute Sylvain Legwinski firing wide.
Anelka was guilty of his glaring miss in the 71st minute.
Kevin Horlock's cross bounced to the far post and the Frenchman, just two yards out, somehow headed wide.
But Anelka made no mistake in the 83rd minute, taking Wright-Phillips' pass in his stride and unleashing a bullet strike into the far corner of Fulham's net.
Sava scooped his late shot into Schmeichel's arms as City held on to win 1-0.