The Garioch swimmer left the field in her wake as she touched in 4min 23.47sec to claim her third medal of the championships, two silver and one gold. It gave her the title she last won in Istanbul three years ago and it was her ninth medal of the event since she first competed in Manchester in 2008.
Miley was the fastest of the qualifiers and she plotted the perfect race in the final as her endurance work paid off. She was third at the halfway point behind the Hungarians, Katinka Hosszu and Zsuzsanna Jakobos, but led at the 300m mark after a strong breaststroke.
The Scot then held off the challenge from the Hungarian duo in the freestyle to strike gold with Hosszu claiming the silver in 4:23.91 and Jakobos bronze in 4:25.61.
"I'm shocked I was that fast," she said, "Last year, I went 4:26 and I was hoping to clock the same time again this week or maybe go a little quicker. To post that time is amazing.
"This week has been good for me, even though it was very tough. I thought Katinka was going to come past me but I dug deep to hold on."
Miley just missed out on a medal in Saturday's 400m freestyle when she finished fourth but set a new Scottish record of 4:00.39. France's Camille Muffat gave the meet it's first world record when she touched first in 3:54.85.
The 23-year-old Scot had a personal best of 28.87 in the 50m backstroke heats but could not get among the medals.
Warrender's Craig Benson reached his first major final when he qualified for the 200m breaststroke by cutting more than two seconds off his personal best in his heat. He lowered that again in the final, where he finished sixth in 2:07.02.