Spain made it three golds out of three in aquathlon at the Association of National Olympic Committees World Beach Games with victory in the mixed team relay.
Their team of individual gold medallists Francisca Tous and Kevin Vinuela won in 1 hour 03min 43sec.
Kseniia Levkovska had given Azerbaijan a substantial advantage as she handed to 2019 world champion Rostislav Petrov for his final swim phase.
"I prayed for someone to give him more power to stay in first," said Levkovska.
In the water, Vinuela overtook Petrov in a move which decided the outcome.
"I tried to push really hard in the swim," Vinuela said.
"I didn't know if I would be able to keep up during the run, but I just tried to concentrate on Pevtsov [during the swim] to catch up."
During the run Vinuela pulled away further and the eventual margin of victory was 12 seconds.
"I'm finished," Petrov said.
"It's like yesterday, I couldn't run after the hot water.
"I couldn't feel my legs. I couldn't feel any power."
Azerbaijan's total time was 1:03:55.
Márti Kropkó and Márk Dévay of Hungary were third in 1:04:29 after Dévay was penalised for an infringement when he left a second pair of shoes in the transition area.
"Unfortunately, I had a penalty because of my lack of knowledge of proper rules, so I took it in the second round, but it didn't really make a difference," Dévay said.
"We would have been third anyway."