Photo: Oscar del Pozo/AFP
Carried along by the slogan “Viva la vida!” (Live life!), drag queens, policemen, activists and politicians made their way through the centre in celebration of sexual diversity and in defence of LGBT people the world over, under the watchful eye of security forces.
Young people mixed with parents and their kids to cheer on as the noise of hovering helicopters blended in with the drums of the march, with onlookers wearing outfits as varied as regular shorts and t-shirts, tight swimwear and sailor uniforms.
Diana Vanegas, a 30-year-old Colombian who lives in California, was on holiday in Spain with her husband and her toddler daughter, who sat in a push chair waving a mini rainbow-coloured flag.
“She doesn't know what the flag represents… but she has to respect people for what they are and not judge them because of their sexuality,” Vanegas said.
As night started to fall and the last marchers made their way through the crowds, police pushed people back and set up barriers to create a larger space along the route and open the road for a parade of 52 floats.
And the party really got started.
Opening the procession was a fire engine with firefighters in gear egging the cheering, whistling crowd on, followed by a slow-moving, music-blaring convoy of open trucks and double-decker buses.
Sponsored by entities as varied as LGBT rights groups, Spain's Socialist party or music streaming site Spotify, the floats all had one thing in common — their occupants danced hard, so hard that their vehicle sometimes swayed from one side to the other.
Authorities and organisers were expecting one to two million people to attend the parade in the 3.1-million-strong Spanish capital, which has become a global reference in LGBT openness.
So far, Madrid city hall had no official count but said “hundreds of thousands” were on the streets of the Spanish capital, drinking and laughing along the way or standing on lampposts to get a better view.
Beyond the fiesta and glitz of an event accused of becoming too commercial, organisers said it was “a political demonstration.”
Pablo Iglesias, leader of far-left party Podemos, and Albert Rivera, head of the centre-right grouping Ciudadanos, were part of the demonstration earlier on in the day, where people held banners in support of those persecuted in other countries, or more generally urging greater tolerance.
Forty years after Spain's gay community started to march for its rights in Barcelona, the country is now held up as an example of LGBT acceptance.
But it wasn't always so.
During the nearly 40-year reign of dictator Francisco Franco — whose rule was blessed by the church in Roman Catholic Spain — homosexual acts were illegal and thousands of gays were shipped off to rehabilitation centres, or even jailed.
Spain emerged from Franco's conservatism in the late 1970s into an exuberant era of liberal reforms and social freedom, with director Pedro Almodovar breaking ground with openly gay and trans characters in his films.
In 2005, Spain became the third country after the Netherlands and Belgium to legalise same-sex marriage.
'Disgusting and inexcusable'
But further afield, the picture is not so rosy.
According to the ILGA, an international LGBT association, intercourse between people of the same sex is still illegal in 72 countries.
The death penalty, meanwhile, is implemented in Iran, Saudi Arabia, Sudan and Yemen, in parts of Nigeria and Somalia, and in territory controlled by Isis.
Jonathan Franklin, a 35-year-old pilot who is half Australian, half Dutch, was dancing in the march with his boyfriend, alongside gay friends from Pakistan and Cuba.
“We have to fight for our rights together,” he said.
“In Holland, we can get married but do you know that in Australia, we are still fighting to obtain gay marriage? Surprising isn't it! Disgusting and inexcusable.”
The WorldPride parade took place against a background of high tension across Europe, hit by a string of attacks, and thousands of police, firefighters and other security agents were mobilised for the event.
Traffic restrictions, bag searches and mobile medical units were also in place.