Mireia Belmonte won the 200 metres butterfly on Wednesday to become the first Spanish woman to win an Olympic swimming gold medal.
The silver medallist in London four years ago went a step better in Rio with a winning time of two minutes, 4.85 seconds, the fastest time so far this year.
Australian Madeline Groves, who went into the race with the fastest time of 2016, took the silver medal and Japan's world champion Natsumi Hoshi won bronze.
Belmonte's gold completed the medal set for the 25-year-old, who won a bronze in the women's 400 individual medley on Saturday, and was also the first for Spain in any sport at the Rio de Janeiro Games.
A silver medallist also in the 800m freestyle four years ago, her four medal career haul makes her Spain's most successful swimmer, though victory was still a haze for her after the race.
"I'm still nervous. Nothing comes to mind," she said when asked what she was thinking about. "The truth is it's everything I dreamed of and it's all happened so quickly."
Her victory was the first for Spain in the Olympic pool since Martin Lopez Zubero won the men's 200 backstroke at Barcelona in 1992.
She still had to work hard for victory, with Groves leading at the first turn after Hoshi had made the fastest start from the blocks.
Groves was also ahead at the halfway stage but Belmonte came back strongly and dashed her rival's hopes of becoming the first Australian to win the event since Susan O'Neill in Atlanta in 1996.
Australians Leisel Jones, Libby Trickett and Stephanie Rice are the last Australian women to win individual golds in swimming, all at the 2008 Beijing Games.
Groves' time of 2:04.88 was still a personal best.
"To come away with a silver medal is just like the best thing ever," she said.
In the other women's final of the night, Katie Ledecky powered the United States to 4x200m freestyle gold to secure her third gold of the games.
Australia held a slender lead over the United States after the third leg, but Ledecky powered through the first 100m to lead by a body length.
From there it was all over, with Australia doing well to hold off Canada to secure silver.
A strong final leg from 16-year-old Penny Oleksiak saw Canada take bronze.