The Blues had taken an early lead through Fernando Torres but Willian equalised three minutes later when he tapped home Fernandinho’s cut-back.
Oscar then restored the defending champions’ advantage when he capitalised on an error from Shakhtar goalkeeper Andriy Pyatov and guided the ball home from 45 yards.
But Willian struck again two minutes after the break to level the tie, before substitute Moses headed home Juan Mata’s corner in the 93rd minute to keep the second-placed Blues level on points with Group E leaders Shaktar.
“We’ve got a crucial three points,” said Di Matteo. “It was crucial for us to win this tough home game. They are a very good side. Now it’s probably going to go down to the last kick of the last game in this group.
“The spirit that my group showed again to keep going to the end – we knew we had to score at the end and we did so. It was good that Victor Moses got on the end of that corner.
“In the first half we put them under pressure which is how we scored both goals.
“We knew what kind of pressure we’d be under and we didn’t want to expose ourselves too much. We knew we could score with the last kick, and that is exactly what happened.
“Oscar has tremendous ability and his goal wasn’t easy at all. It was a half-volley, very difficult, but he is a Brazilian international.
“John Terry is a massive player for us and we’re glad he’s back and available for us. He is going to be our leader going forward.”
MORE: Man United latest news
MORE: Arsenal latest news
MORE: Chelsea latest news
MORE: Liverpool latest news