c.1300, from Old French ma dame, literally "my lady," from Latin mea domina (cf. madonna). Meaning "female owner or manager of a brothel" is first attested 1871.
1590s, see madam, which is an earlier borrowing of the same French phrase. Originally a title of respect for a woman of rank, now given to any married woman. OED recommends madam as an English title, madame in reference to foreign women.