Marcus Rashford and Mason Greenwood also got themselves on the scoresheet as United booked their place into the fifth round of the competition. Mohamed Salah scored his first goals at Old Trafford with a brace but Liverpool's winless run goes on.
Greenwood had two chances early on but Alisson saved the first and the second went past the post. Liverpool started to dominate possession thereafter and took the lead in the 19th minute when Roberto Firmino slipped in Salah, who dinked the ball over Dean Henderson.
United equalised eight minutes later with a quick counter attack that saw Rashford clip a brilliant pass to Greenwood, who finished into the bottom corner for his first goal since Dec. 5.
The hosts took the lead three minutes after half-time when Greenwood set up Rashford to finish, but Liverpool responded well and Salah grabbed his second on 58 minutes, just after James Milner missed a sitter.
Salah then went close to completing his hat trick on the break, but shot straight at Henderson. It was a miss Jurgen Klopp's side would come to rue, as substitute Fernandes made a decisive intervention.
After Rashford left with a knee problem on which Solskjaer said he will have a scan on Monday, Cavani almost made it four in the 90th minute but his header clipped the post.
"Brilliant -- you know when you go a goal, down the reaction of everyone was really good," Ole Gunnar Solskjaer told the BBC. "We played some really good stuff, good goals, we have to defend well against them and we managed to react well and of course towards the end there were some moments but we kept them away."
"Great goal, good free kick," United's manager said of Fernandes. "When you leave him out like I did today, he stayed about 45 minutes after training yesterday shooting free kicks so I was pretty confident he could score one if he got the chance. He's never happy with me when I tell him to go inside after training when he's playing the next day so he got some practice yesterday."
It was the first time that Liverpool have lost back-to-back matches in all competitions since March 2020.
"There was a lot of good things and some mistakes around the goals," Jurgen Klopp told BBC. "If you want to win here you have to be absolutely top and we were not.
"We can take things out of this game, we try to learn from every game. It's good for Mo Salah, good for the confidence. It was a tough game. We want it hard but tonight it was not enough."