Chris Froome extended his overall lead in La Vuelta after Miguel Ángel López, the Colombian rider, won the short but sharp 129-kilometre 15th stage from Alcalá la Real to Sierra Nevada.
Nibali, who did not compete in this year's Tour, waited his turn to attack while Alberto Contador, Romain Bardet (AG2R) and Lopez formed a group ahead of Froome's bunch.
A late surge by Froome over the final meters of the punishing ride and a final special-category ascent allowed him to increase the gap over Vincenzo Nibali from 55 seconds to 1:01.
"I tried my best so I can't be disappointed with that".
Russia's Ilnur Zakarin was second behind Lopez, 36 seconds off the pace, with Wilco Kelderman third.
Victory also moved Lopez up to sixth overall, ahead of Astana teammate and 2015 Vuelta victor Fabio Aru.
Majka's chances in the general classification were undone by illness in the first week, which almost forced the Bora-Hansgrohe rider to abandon the race.
Brush Fire Threatens Homes In La Tuna Canyon
Firefighters said erratic fire behavior caused by strong, gusting winds made it hard to predict what areas may be at risk. Firefighters sent additional resources to that neighborhood for structure protection and to assist with evacuations.
Trentin has now won six grand tour stages, his treble here adding to two Tour wins and one in the Giro in 2016.
The three-time Tour de France victor is looking to add his name to the cycling history books by becoming over the third person to win the France and Spain challenges in the same year; if he's successful, it will be the first time since 1978.
"I came to the Vuelta for the GC and I'm sick, I nearly go home, but now I am so happy. It didn't work out today but I am sure it will in the future".
From the break and a party to only 10 km from the goal, Majka, 27 years old, has held off the favourites to clinch his first stage victory on the Vuelta.
The point keeps France on top, one point ahead of Sweden, which earlier beat Belarus 4-0 in Borisov.
Chris Froome retained his place atop the general classification after finishing as part of a chasing trio not far off the victor in Saturday's 175-kilometre ride from Ecija in southern Spain.