So this is relatively common knowledge among music fans these days, but I figured first I'll give a little background about disco, since I think it's kind of essential to understanding its decline. So discotheques, which originated in Europe, started coming to the United States in the 1940s. Since the point of a discotheque is, you know, to dance, music genres with danceable rhythms became popular things to play and dance to in these clubs. Since a lot of black music genres (go-go, rhythm and blues, funk) were very danceable, they tended to get played in these clubs and formed the basis for what would become disco. When innovative artists started fusing funk and soul with psychedelic rock pioneered by people like Jimi Hendrix, you started seeing songs that more and more represented what disco was eventually going to sound like. Disco began to really hit the mainstream in the early 70s, and dominated for most of the decade.
It's also important to understand the type of people who were at these early disco clubs. At least in the US (there was also a European disco movement), the early clubs were dominated by black and gay people, since early disco clubs were private and they were less likely to be harassed by the police or arrested there.
By the mid-70s, disco really started to take off in the mainstream, with smashes like Rock the Boat, Kung Fu Fighting, I Will Survive and a slew of other disco hits topping the Billboard charts. Traditionally Motown artists, seeing the success of disco, also started getting involved. Diana Ross came out with hits like I'm Coming Out, and the rest of the Supremes also had a few disco hits without her. Even Marvin Gaye made a disco song (Got to Give It Up) despite the fact he really didn't like the genre. Disco also became extremely popular in Europe with groups like Boney M. and ABBA and artists like Donna Summer (who was American, but Moroder and Bellotte, the producers who worked with her on some of her major hits, were German, and Summer had been living in Germany).
A major moment for disco came in 1977 in the form of Saturday Night Fever, which was largely soundtracked by the Bee Gees. The film spawned a few massive disco hits including Stayin' Alive and Jive Talkin', among others. What made this different from most of the previous disco hits was in who was singing it; the Bee Gees were all heterosexual, white men, which (as far as some people are concerned, anyway) helped the genre to finish its crossover to the mainstream by finally appealing to straight white guys. For a few years, it seemed like disco really had won -- Donna Summer had a slew of top 5 radio hits with disco songs, and pretty much everyone started incorporating disco sounds into their music, from the disco-inspired drums in Pink Floyd's Another Brick in the Wall, to Ringo Starr's disco-influenced album Ringo the 4th, to truly stupid novelty hits like Disco Duck (sorry to anyone who likes that song).
The backlash to disco came partially from this sort of overexposure (it really was everywhere), but especially from rock fans, who saw the genre as escapist, consumerist, and overproduced, which was contrary to all the central tenets of rock at the time. Rock in the late 70s really emphasized getting back to basics, so artists like David Bowie who were clearly influenced by the genre were accused of "selling out". Disco also came into conflict with the rising punk genre (though a lot of punks were also disco fans -- John Lydon/Johnny Rotten, from the Sex Pistols, was a huge fan). The Dead Kennedys, for example, wrote a song called Saturday Night Holocaust comparing disco and the culture that surrounded it to Weimar cabaret culture (life's a cabaret / like in Berlin, 1930 / all I crave is my escape), accusing disco fans of essentially sticking their heads in the sand and ignoring all the awful things going on in the world (in typical Dead Kennedys fashion, the narrator gets carted off to Auschwitz at the end but barely even notices or cares).
Probably the most infamous example of this anti-disco sentiment was the Disco Demolition Night organized by the Chicago White Sox, where a crate of disco records were blown up by the White Sox (damaging their field so badly that they had to forfeit their next game). Rock fans who'd come to see the disco records be destroyed were so overjoyed that they actually rushed the field, tossed around the records, and had to be dispersed by riot police. Disco declined pretty quickly after this event, though it can't be solely credited. Nonetheless, it probably hastened things along.
There are a few main reasons for disco's decline (in my opinion, anyway). First, it's pretty natural for music movements to rise and fall as people get bored due to overexposure and look for something else. If you look at the charts from the 2010s to now, for example, you can track the rise of moody trap music and can see its popularity start to wane as new genres start to gain on it (nu-disco is even one of these genres!). After a decade of disco dominance, people were just ready for something new.
However, I think this answer would be really incomplete if I just left it at the natural progression of trends. The backlash against disco was really extreme and angry, and I don't think being tired of the genre fully explains it. Disco was a primarily black and gay genre at a time (the late seventies and early eighties) where the United States was becoming more conservative and focused on the "traditional" family. Disco, which was seen as hedonistic and unmanly, didn't work with this cultural shift at all. The homophobia and racism angle can't really be overlooked here. As Harold Childs, senior vice president at A&M, told the LA Times, radio was "looking for some white rock-n-roll" to play, rather than disco. Some disco artists like Gloria Gaynor have also attributed to the backlash from the music industry to essentially jealous rock stars and producers who were angry that they were starting to be surpassed by disco.
I wouldn't necessarily say disco ever "died" though. Tons of currently popular genres owe their existence to disco, with early hip hop, post-punk and new wave music, and 90s house being the clearest examples. The 1990s also saw a big resurgence of disco as part of the 1970s nostalgia, with hits like Groove is in the Heart (an absolute earworm) and movies like Boogie Nights. I'd also point to nu-disco, which started in the 2000s and spawned modern classics like Can't Get You Out of My Head by Kylie Minogue or Madonna's whole Confessions on a Dancefloor album. That's over 15 years ago now, but modern acts like Daft Punk also make very disco-inspired music that charts very well (Get Lucky, for example), and just last year Dua Lipa's very disco-influenced Future Nostalgia totally smashed (Levitating from the album is still #3 today despite coming out over a year ago).