The very first undergarments were the loincloths of ancient people. Although primitive tribes ran around naked, after a while people became self-conscious about their nudity and covered their genitals. The breasts of women were still open for a long time.
The first purely female underwear, consisting of panties and a bra, was invented in... Ancient Greece. They were also a kind of bandage, but in the version to which we are accustomed today. Under the tunics and togas women did not wear underwear. And it was invented for female athletes - especially for training and competition, because in Greece there were not only the Olympic Games for men, but also the Heraeus Games for women.
About the "suffering Middle Ages" it's even scary to talk about - there under the huge skirts you could not find underwear at all, and if it was, it hadn't been changed for weeks... Let's talk better about the turn of the 19th-20th centuries. Underwear for women at that time meant not only pantaloons, but also stockings, which should have reached to these pantaloons, a top shirt, corset over it, underskirt, and often there were several of them.
The first bra was made from... two halves of a handkerchief. It was invented in 1914 by American Mary Phelps Jacobs. She liked to wear open dresses to receptions, and she was always embarrassed by the corset peeking out of the cut on the back. Although this bra was not a novelty, it was the one that really made history. Mary sold her patent for $1,500, and the company that bought it made $15 million on the invention within a few years.