Fanfic (fanfiction) has always existed in one form or another – stories of heroic characters told around the campfire were pure fanfic, each storyteller not so much inventing new stories as developing and enlarging the tales that they had been told.
The modern form of fanfic, where fans of a particular genre write their own stories involving their favourite fiction characters, grew out of the science fiction sub-culture during the 20th century. The rise of the internet gave the fanfic writers a whole new playground, where they could share their stories with other fans across the globe. Consequently, the genre grew a number of subgenres; one of them, slashfic, is specifically about sexual (usually, but not always, gay male) pairing between characters. (The term derives from early Star Trek fanfic, where sex-related pairings were were given shorthand labels such as Kirk/Spock.)
Rather disturbingly, slashfic is not confined to fictional characters. Thanks to a Live Journal comment I have learned of the existence of Football Slash. Yes, really. Fictional gay sex stories involving international footballers.

I daren’t read the Ronaldo/Rooney one.