Unavoidable during the past few months on both the internet and the radio, this sleek – and surprising – collaboration between Justin Bieber and two of Puerto Rico’s biggest stars, Luis Fonsi and Daddy Yankee, is without question the song of the summer.

It’s sold more than 2 million downloads. It’s been streamed on Spotify nearly 800 million times. It spent 16 weeks at No 1 on Billboard’s Hot 100 – matching the record for the most weeks spent atop of the US music singles chart with Mariah Carey and Boyz II Men’s One Sweet Day (1995-1996).

“If you’d told me a few months ago that the song was still going to be No 1 in August, I would’ve been like, ‘There’s no way – people are going to be sick of it’,” Fonsi says with a laugh. “But here we are.”

The success of Despacito, whose title translates to “slowly”, is to some extent an artistic triumph. A seamless blend of pop and reggaeton, the expertly crafted song about a sexual encounter zeros in on an emotional and aesthetic sweet spot; it strikes an ideal balance of melody and rhythm, romance and lust.

But it also happened in the right place at the right time. Sung mostly in Spanish, Despacito has resonated with many listeners this year as an implicit counterpoint to American President Donald Trump’s tough rhetoric regarding Latinos and immigrants from Latin America.

Indeed, Bieber’s manager, Scooter Braun, says his principal motivation in putting the remix together was the idea of topping the Hot 100 while Trump was in office.

“A song in Spanish is all over pop radio in an America where young Latino Americans should feel proud of themselves and their families’ native tongue,” Braun says.

That political edge wasn’t necessarily in Fonsi’s mind when he and Erika Ender, an experienced songwriter from Panama, came up with the tune in 2015. According to Ender, who’s also worked with Mexican musicians Gloria Trevi and Los Tigres del Norte, Despacito was born one afternoon at Fonsi’s house after the two friends had caught up over coffee.

“We started writing around 3pm and finished around 6pm with the song completed from top to bottom,” Ender recalls. “We were looking for a very contagious melody, and it came very easy.”

Well known among Latin pop fans as a sensitive balladeer, Fonsi wanted a different kind of production for the recorded version of Despacito – an “evolution” of his signature style, as he described it, with a pronounced “urban” vibe.

So after trying out a number of approaches, Fonsi and his producers sought out Daddy Yankee, one of the driving forces behind reggaeton’s synthesis of hip-hop and more traditional Latin music. (Even casual pop listeners are likely to recall Daddy Yankee’s Gasolina, which caught fire in the US in 2004.)

The duo’s original take on Despacito came out in January 2017 and blew up immediately in Latin America, thanks in large part to widespread sharing of the song’s video on social media, says Jesus Lopez, who oversees Universal Music’s Latin division.

Lopez is an industry veteran who helped make hits of Iglesias’ Bailando and Los Del Rio’s Macarena – the latter was the last Spanish-language song to top the Hot 100, more than two decades ago. Lopez says he’s never seen a song grow as quickly as the original Despacito, whose video has the most views of any clip on YouTube: 3.6 billion at last count.

Yet the song wasn’t just attracting young people attached to their phones. Lopez recalled watching Fonsi perform Despacito in concert earlier this year and seeing him inspire a diverse audience to sing along – “from kids to grandparents”, the executive recalls.

Still, there was a crowd the song hadn’t quite won over by the beginning of April, and that was mainstream American pop fans. Ender says she, Fonsi and Daddy Yankee wrote an English translation of Despacito in the hopes of getting an American singer to take part in a remix.

Monte Lipman, chairman of Republic Records, said he’d spoken with Braun (whose other clients include Usher and Ariana Grande) about various strategies for breaking the record in the US.

But the singer they got wasn’t one they’d been courting. According to Braun, Bieber (who is Canadian) heard Despacito in a club while on tour in Colombia. After seeing the room react to the song, he got in touch with Braun and asked the manager what he thought about lending his voice to a new version.

Braun liked the idea, but Bieber wanted to move fast. So the manager called Poo Bear, a songwriter and producer with whom Bieber has collaborated closely in recent years, and had him get to work that night on a fresh verse for the singer.

The verse Poo Bear wrote – and quickly sent to Bieber in Bogota – was in English, which Braun figured would help ease American listeners into the song. (Sure enough, Bieber’s verse about “the way you nibble on my ear” comes first in the remix, right after that fluttering cuatro.)

Yet Braun says his client wanted to sing in Spanish. “What’s the point of doing a gigantic Latino record unless you’re going to do it for the Latino market?” Braun says the singer asked.

That thinking aligned with Braun’s own ambition to counteract what he saw as an anti-immigrant movement by which “young Latino American kids were ... being told that speaking Spanish made them un-American”.

So, in a reversal of crossover-record protocol, Bieber recorded the song’s chorus in Spanish, learning the lyrics over the course of a four-hour session in a Colombian studio, Braun says.

Fonsi says the gesture struck him as “very brave”. And audiences responded: released in mid-April, the remix of Despacito hit No 1 on the Hot 100 a month later and remained there until Taylor Swift’s new single Look What You Made Me Doedged the remix into the No 2 slot this week.

The two record executives behind the song, Lopez and Lipman, both point to streaming as a crucial component of the song’s success.

According to Lopez, the numbers Despacito was racking up on YouTube and Spotify offered proof to traditional gatekeepers – radio programmers, television talent bookers and the like – that demand for the record was high. And that sped up Despacito’s journey towards more old-fashioned media plays, which, in turn, led to further action on the new streaming platforms.

Not that the song’s popularity insured Bieber, a reliable lightning rod for both positive and negative attention, against all criticism. When video surfaced online showing Bieber struggling to sing along with Despacito in a New York nightclub – “I don’t know the words, so I say Dorito,” he appears to sing – many observers accused him of the precise kind of cultural insensitivity Braun says he was working against.

The manager deflected that idea, saying Bieber doesn’t speak Spanish and has never claimed to – which is why, he added, the singer has never properly performed Despacito in concert.

“I think that whenever you have great success, you’re going to have some people who want to tear it down,” Braun says. “But at the end of the day, the guys made a great song.”