Victor Casadesus gave Gregorio Manzano's side the lead but a wonderful goal from Silvio put Deportivo back on level terms. Carlos Marchena gave the visitors the lead early in the second half and Riki extended their advantage, before Alfaro scored a late goal to set up a tense finish.
It was the fist time the Galicians had won away from home this season and although they remain bottom of the Spanish League table, they moved to four points from exiting the relegation zone and survival is now a realistic possibility for Fernando Vazquez's side.
With both teams in the relegation zone and fighting for their lives it was always going to be a hard-fought game, but Deportivo's players produced flashes of brilliance and overall were worthy of the three points.
Mallorca goalkeeper Dudu Aouate nearly got his team into trouble early on when he came to punch a cross and fell to the ground, but recovered in time to grab Aythami's weak effort.
The hosts took the lead after 20 minutes. Alfaro ran onto a pass over the top from Giovani dos Santos but mis-controlled the ball, which, with the help of a slip by Marchena, landed at the feet of Casadesus. His shot from just outside the area took a slight deflection off Silvio, which took Deportivo goalkeeper Dani Aranzubia by surprise and he was powerless as he watched the ball trickle into the net.
Silvio soon made amends with a sensational equaliser. The Portuguese, who joined Depor on loan from Atletico Madrid in the January transfer window, picked the ball up on the left-hand side, used great skill and close control to beat three defenders before curling a right-footed effort into the far corner. It was the left-back's second goal in as many games.
Deportivo took the initiative in the closing stages of the first period. Pizzi should have given them the lead but he could not beat Aouate from close range, while Alfaro and Giovani both came close to scoring for Mallorca before the break, from a corner and a free-kick respectively.
Deportivo took the lead for the first time in the game just minutes into the second half. Pizzi sent in a dangerous cross from a free-kick, which Abel Aguilar headed towards goal. Aouate failed to deal with the danger and the ball fell to Marchena from just yards out, and the centre-back gratefully side-footed home.
Mallorca brought on joint top-scorer Tomer Hemed in place of Casadesus in search of an equaliser but the game was all but over for the Islanders just a few minutes later.
Pizzi burst into the box and beat a defender in style but could only hit his shot at the feet of Aouate. But, in an unfortunate turn of events for Mallorca, the ball bounced up into the air and off the head of Alfaro and into the path of Riki, who headed into an empty net.
Hemed had a chance to pull one back for Mallorca shortly after the third Depor goal, but blasted a cutback from Pina well over the crossbar.
Alfaro did eventually get a goal to give Manzano's side hope, bundling the ball over the line a yard out, but despite late pressure Mallorca failed to penetrate the Deportivo defence and the Galicians held on for a crucial victory.