Michael Owen ended his goal drought after just 3 minutes when he dribbled past Richard Dunne before chipping over David James.
Steve McManaman's run and pass on 50 minutes set up Shaun Wright-Phillips to fire the equaliser across goal and into the far corner. But just a minute later sloppy defending and a fumble from James allowed Steven Gerrard to hit the winner.
The City boss said: "We played some good stuff and were unfortunate to end up with nothing. The second goal was a bad one to concede from our point of view.
"It was scrappy, a mistake here and a bit of slackness there, but if you do that in the Premiership you get punished."
Keegan added: "It has been a tough run for three months so it cannot get any worse in the next few weeks. We have Manchester United twice, Chelsea and Bolton. If we can repeat that second-half performance week in week out, we will get up the table. But if we play like we did in the first half it will see us in a relegation dogfight.''
"My job is to keep the spirits up," said Keegan. "I believe in these players, they have been a very, very unlucky team but you cannot hide from the results.
"But if you try to tell me there are 15 places between us and Liverpool after this performance, I just do not see it. We will just keep soldiering on and try to turn it around at Old Trafford on Saturday.''
Liverpool boss Gerard Houllier opted for a safety first approach in the final moments as he sought to defend his side's one goal advantage but the home fans showed their disapproval by booing.
Houllier said: "You have to understand that when you play a good team it cannot all be one-sided. You have to give Manchester City respect. There were spells when they were better, I watched them even at Arsenal and they were unfortunate.
"First of all it is a good win, a good three points against a good team who can play good football."