Victor Moses scored on the last touch of the game off of a corner kick by Juan Mata.
The Blues went on top early through a sixth-minute Fernando Torres goal.
After an equalizer by Willian, Oscar scored a brilliant goal off of a mistake by Shakhtar keeper Andriy Pyatov.
Willian equalized again for the visitors in the second half, and it took until the final touch of the match for Chelsea to secure a victory.
Here are six things we learned from the dramatic win by the Blues.
The first two goals scored by Chelsea were off of mistakes by Shakhtar Donetsk keeper Andriy Pyatov.
The first goal came in the sixth minute from Fernando Torres, who took advantage of a poor clearance by Pyatov and had the ball bounce off his leg into the net.
The second mistake by Pyatov led to a brilliant goal by Oscar in the 40th minute.
Pyatov's clearance went right to the feet of the Brazilian, who then produced a quality goal from near midfield.
If it was not for those two mistakes by Pyatov, it could have been a completely different match.
The second goal scored by Chelsea was one with a trademark of Brazilian flair all over it.
Oscar took a gift from Pyatov's clearance and sent it over the Shakhtar keeper and into the back of the net.
The 40th-minute goal was not just a piece of brilliance by the Brazilian midfielder, but it gave Chelsea the lead going into halftime and the momentum after a strong first half by the visitors.
The goal is the fourth of the season for Oscar, all of which have come in the Champions League.
If it was not for the crucial errors by Andriy Pyatov, the focus on David Luiz's horrible play in the Chelsea defense would be focused on as the worst performance of the match.
There were plenty of times during the match where Luiz had trouble with his clearances and almost led to chances for Shakhtar.
Luckily for the Brazilian defender, none of his mistakes resulted in goals for the visitors.
Look for Luiz to be benched due to the return of John Terry on Sunday against Liverpool in the Premier League.
Fernando Torres has not had the best past few weeks, but the Spaniard has stayed in the Chelsea starting lineup and rewarded manager Roberto di Matteo with a solid performance on Wednesday.
Torres' goal in the sixth minute was caused by the horrible error of Pyatov, but Torres was still able to hurry the keeper and score the goal.
The Chelsea No. 9 also created more chances throughout the match with four shots before he was taken off for Daniel Sturridge in stoppage time.
Victor Moses played the role of hero for Chelsea on Wednesday night with his goal in the fourth minute of stoppage time.
Moses' head connected on the end of a Juan Mata corner kick to give the Blues a vital 3-2 win at home.
The Nigerian has not been used by Roberto di Matteo much this season, but he has scored a goal in each of the last two matches for the Blues.
If Moses continues to score goals, di Matteo will have no choice but to start him.
With Wednesday's win, the Blues did move to the top of the Group E table, but by the slimmest of margins.
Chelsea and Shakhtar Donetsk are tied with seven points each, with the Blues holding the advantage in goal differential.
Just behind the two clubs is Juventus, who won easily at home against Nordsjaelland on Wednesday, with six points.
The next Champions League match for Chelsea will be in Italy against Juventus.
For Roberto di Matteo and company to not have to worry about qualification on the last match day against Nordsjaelland, they have to take points from the Italian champions.
A win would be the best result for the Blues, but a draw would not kill the hopes of advancing to the knockout stage.