Harem is genre in Anime and Manga involving a Male protagonist surrounded by girls who have feelings for him
Harem is a popular genre in the anime/manga industry but what are the origins of how it become one of Anime and Mangas popular genres?
The first anime or manga to have all the elements of the harem genre is Tenchi Muyo! Ryo-Ohki (OVA anime: 1992). It has multiple female characters pursuing the same male lead, a constant presence in his life, in this case living with him in the same house. Like most examples of this genre the main character acquired his harem accidentally and doesn't actually want all these women pursuing him. Also like many examples of the genre the female characters are very extraordinary, far from ordinary Japanese girls.
You can see the origins of the genre in other manga and anime series that had many of the same tropes but never put them all together. For example Oh My Goddess! (manga: 1988, OVA anime: 1993) has three goddesses living in the same house with the main character, although only one is interested him romantically. Ranma 1/2 (manga: 1987, TV anime: 1989) has a main character with a number of different suitors over the course of the long series, both female and male, but they don't form a harem as most of these characters only make occasional appearances.
A likely influence of harem genre is the reverse harem genre. While you'd think from its name the reverse harem genre came later, the trope of a woman with many suitors is probably old as storytelling. The suitors of Penelope in the Odyssey (ca. 700 BC) were 108 men who pursued Penelope, the wife of the presumed dead Odysseus, while all living together in his home. While the Odyssey probably wasn't a direct influence on the genre, shoujo romance series like Fushigi Yuugi (manga: 1992, TV anime: 1995) and Hanasakeru Seishounen (manga: 1987, TV anime 2009) have pretty much all the elements you'd expect in the harem genre except with the male/female roles exchanged.
Another possible influence would be love triangles appearing various male oriented series like Maison Ikkoku (manga: 1980, TV anime: 1986) and Kimagure Orange Road (manga: 1984, TV anime: 1987). Yet another possible influence are dating sim and ren'ai visual novel games were the player can pursue one or more of a number different love interests. While the structure is different, when these games get turned into anime shows they're often become harem anime.
As for why the harem genre is popular it's hard to say. The obvious answer is that it provides the stereotypical shy-with-women male otaku with a sort of escapism and wish fulfillment they can't get from other genres. However I don't think it would be as popular if it was just that. I think subverting the age old trope of a woman with many suitors is a big part. It provides a lot comedic potential in what in real life would seem absurd: a number of always attractive and usually exceptional women all openly pursing the same ordinary looking usually kind of awkward guy.