Elche clinched Primera Division survival by battling to a 2-1 win at Malaga in a thrilling game at La Rosaleda, in which the visitors survived conceding a late penalty and having a man sent off.
Jonathas de Jesus scored his 12th goal of the season to give the visitors a first-half lead but Malaga, who had three goals disallowed over the 90 minutes, should have levelled in the second half when they were awarded a penalty and Elche goalkeeper Przemyslaw Tyton was sent off for bringing down Javi Guerra.
However, Duda hit the woodwork from the spot and then Chelsea loanee Mario Pasalic sealed the points by finishing off a smooth counterattack.
Javi Guerra pulled one back in the 94th minute and could have even grabbed an equaliser in the final minute of stoppage time, but Elche held on to jubilantly celebrate securing top flight status for a second year in a row.
Earlier this weekend Malaga surrendered seventh spot in the table to Athletic Bilbao and they looked as though they had a point to prove, making a strong start to the game.
Forward Juanmi headed a cross from Samuel Garica into the net with 16 minutes gone but the effort was correctly ruled offside.
Elche, as they have been doing for most of the season, sought to sit back and soak up the pressure and hit their opponents on the break.
They did that to devastating effect on 29 minutes. Faycal Fajr released Victor Rodriguez down the right and the midfielder rolled the ball across the box for Jonathas to dispatch into the net.
Malaga missed a couple of chances to equalise before half-time but came out with even more determination in the second half.
Nordin Amrabat shot straight at Tyton early in the second period, Arthur Boka skewed a shot wide and then the hosts had another goal disallowed when Amrabat was adjudged to have pushed Tyton as he attempted in vain to stop a looping cross from going in.
Mario Pasalic could have put the game to bed long before he did but shot wide of the near post with just Carlos Kameni to beat.
Malaga were allowed the perfect way back into the game on 70 minutes when substitute Guerra was tripped by Tyton, who was shown a straight red card, but Duda, also a substitute, hit the post from 12 yards.
Substitute goalkeeper Manu Herrera was kept busy in the few minutes he was on the pitch but Elche looked to wrap up the game in the 88th minute. Malaga had committed so many men forward, allowing Jonathas to lay the ball on for Pasalic to beat Kameni.
There was still more drama to come, however. Guerra converted on the rebound after Amrabat's enterprising effort hit the bar, and the Spaniard had a glorious chance to level in the 96th minute but shot straight at Herrera.
ends
La Liga News
Real Madrid's special Vinicius Junior on the verge of silencing his critics in Spain
Despite his harsh critics in Spain, Vinicius Jr. is thriving and growing as a player in Madrid in a manner that will soon silence his doubters.
Weekend Overreactions: Juventus won't win Serie A?
Steve Nicol examines whether these takeaways from this weekend in world football are overreactions.
Real Zaragoza match-fixing case: 41 people cleared including Leganes boss Javier Aguirre
A Spanish court has cleared 41 people and Real Zaragoza of match-fixing charges in a Liga fixture between Levante and Real Zaragoza in 2011.
Weekend numbers: Messi beats Ronaldo, Guardiola's worst ever start
Ole's men stunned City, Juve finally lost and Messi grabbed a record hat-trick: Here are the best numbers from weekend football.
Sevilla lag behind La Liga frontrunners after Osasuna draw
Sevilla slipped further behind La Liga pacesetters Barcelona and Real Madrid on Sunday after being held to a 1-1 draw away to Osasuna.
Getafe close gap with Sociedad in race for fourth
Real Sociedad clung on to fourth place in La Liga after a goalless draw against Real Valladolid.