Malaga welcomed Elche to La Rosaleda on Sunday looking to end a run of seven games without a win in La Liga.
The visitors led 1-0 at the interval courtesy of a close-range finish from Jonathas.
Elche were reduced to 10 men in the 72nd minute when Polish goalkeeper Przemyslaw Tyton was sent from the field for pulling Javi Guerra to the ground inside the box, but the resulting penalty from Duda struck the post.
The away side scored their second late on when Mario Pasalic converted a cross from Jonathas, before Guerra scored what proved to be a consolation for Malaga in the fourth minute of added time.
Fran Escriba's Elche can no longer be relegated from Spain's top flight via their league position.
Read how it all unfolded in Sports Mole's minute-by-minute live commentary of the action below.
MAL: Kameni; Rosales, Sanchez, Weligton, Boka; Darder, Camacho; Samu, Amrabat, Castillejo; Juanmi
ELCHE: Tyton; Cisma, Lomban, Roco, Suarez; Mosquera, Pasalic; Victor, Fajr, Rodrigues; Jonathas