Image copyright Reuters Image caption Lil Nas X, right, recently released a remix of his song with Billy Ray Cyrus, left

Old Town Road, the viral rap song by Lil Nas X, has become the longest-running number one in US chart history.

The song has now topped the Billboard Hot 100 for 17 weeks, overtaking Luis Fonsi's Despacito and Mariah Carey's One Sweet Day, which both spent 16 weeks at number one.

It had 72.5 million streams and 46,000 downloads in the past seven days.

Carey sent "love and congratulations" to Lil Nas X, after hearing her 26-year-old record had been smashed.

The rapper, a college dropout from Atlanta, whose real name is Montero Hill, recorded the song last October, using a backing track he bought online for $30 (£24.70).

With its blend of country music and trap beats, it achieved notoriety on the social media app TikTok, where thousands of people filmed themselves lip-syncing to the song in cowboy boots and ten-gallon hats.

By March, he had signed a deal with Columbia Records, and the song gained early press coverage after Billboard banned it from their country charts, for allegedly failing to "embrace enough elements of today's country music".

The decision attracted criticism over the conservatism of the country establishment, as well as accusations of racism. Billboard denied that race played any part in its ruling.

Nonetheless, the added attention helped Old Town Road rise up the main charts, eventually hitting number one in April.

Its tenure at the top has been extended by the astute tactic of releasing remixes and alternate videos to top up its streaming numbers.

The most popular remix features country star Billy Ray Cyrus, while other versions contain cameos from Young Thug and RM of the K-pop band BTS.

And while the original video was created using footage from the Wild West video game Red Dead Redemption, the "official" clip - released in the seventh week of its chart reign - is a big-budget production featuring cameos from Chris Rock, Diplo, Vince Staples and Rico Nasty.

All the different versions of the song are close enough to the original, and so count towards one single total in the US charts.

Media playback is unsupported on your device Media caption Lil Nas X told BBC Breakfast he felt like he was "opening doors for more people"

On hearing that he'd toppled the Billboard record, Lil Nas X posted a long essay explaining the origins of his song.

"I went looking for beats on YouTube... when suddenly I came across a country-trap-sounding masterpiece," he wrote, "I immediately knew I would make something special out of it.

"I jokingly/seriously saw myself as a loner cowboy, needing to run away from it all. I went out on my sister's porch and listened to the beat over and over. Then it came to me!"

He added: "This song has changed my life and the way I see the world around me in less than a year.

"I'm so thankful this blessing has been placed upon me."

The rapper also shared a few photos documenting the rise of Old Town Road, including a short video of him and Billy Ray Cyrus in the studio, on his Instagram account.

During the star's 17 weeks at number one, seven separate songs have peaked at number two - most notably Billie Eilish's Bad Guy, which has spent seven weeks in the runners-up position.

Old Town Road has also clocked up 18 weeks on the UK singles chart, two of them in the top spot.

Follow us on Facebook, or on Twitter @BBCNewsEnts. If you have a story suggestion email entertainment.news@bbc.co.uk.