Jose Mourinho's second-half substitutions proved crucial as the capital club fought back with goals from Kaka and Gonzalo Higuain overturning Riki's opener
The Blancos took a while to get going in Galicia and their inability to create in the final third cost them as Riki put the hosts ahead in the first half. Jose Mourinho used all three subtitutes shortly before the hour mark and it proved to be a masterstroke. Kaka got the equaliser in the 73rd minute before Gonzalo Higuain provided the crushing blow to the hosts with two minutes of normal time remaining.
Cristiano Ronaldo and Mesut Ozil were among the players rested for Madrid, and Deportivo looked to take advantage by beginning the game positively. However, Madrid refused to sit back and a 15th-minute free kick offered them a chance to silence the hosts.
Angel Di Maria was handed the responsibility of taking the set piece, and he arced a powerful effort to Daniel Aranzubia's left that the keeper was forced to turn behind the post.
Mourinho's men soon monopolised the ball but were lacking a cutting edge in order for them to forge clear-cut opportunities.
The longer that the Galicians kept the score level, the more confident they became, however, and two brilliant efforts from Pizzi in quick succession were hit narrowly off target.
But in the 35th minute Riki did not make the same error. Running in behind Pepe to latch onto Pizzi's through-ball, the veteran striker struck a low, powerful effort to Diego Lopez's near post and the goalkeeper was unable to keep it out.
There could well have been a second for the hosts before the break as Paulo Assuncao released Pizzi moments before the break. The Portuguese skipped inside of two Madrid defenders and beat Lopez with a curling, cross-goal effort but Marcelo got back to clear it off the line.
The Blancos began the second half with much more vigour but despite Jose Callejon's lively runs, he was unable to direct a pair of attempts on target before Marcelo's shot was blocked en route to goal by Abel Aguilar.
With 57 minutes on the clock, Mourinho played all his cards at once by introducing Ronaldo, Ozil and Sami Khedira to the action.
The substitutions had a galvanising effect and Madrid finally pulled level in the 73rd minute. Kaka received the ball in space at the top of the box and he placed his shot perfectly, curling an effort just inside of the post.
Deportivo were clinging to the draw from then on and it took a great save from Aranzubia to deny Ronaldo in the 78th minute after the forward had skipped past Alex Bergantinos.
The Portuguese saw a header shade the outside of the post moments later but he was instrumental in the winner that came with two minutes of normal time remaining. Kaka's through-ball was unselfishly laid across goal by Ronaldo, offering Higuain the simplest of finishes to steal all three points.
Di Maria was dismissed for picking up two bookings in quick succession after ignoring the referee's demands to retreat from the Deportivo free kick.
But Madrid still secured the win which ensures that Barcelona will remain within 16 points at the top of La Liga while Deportivo remain rooted to the bottom of the table.