ASCAP, the older of the two organizations, was founded in 1914, primarily to protect copyrighted material coming out of New York City's Tin Pan Alley, which at that time was home to many of the era's most prominent songwriters and composers. According to its website, ASCAP now has more than 390,000 members as well as hundreds of thousands of international music creators that it represents in the U.S. through agreements with affiliated societies.
According to its website, "BMI was founded by radio executives to provide competition in the field of performing rights, to assure royalty payments to writers and publishers of music not represented by the existing performing right organization and to provide an alternative source of licensing for all music users." BMI "was the first to offer representation to songwriters of blues, country, jazz, r&b, gospel, folk, Latin and, ultimately, rock & roll."
BMI and ASCAP work the same way. They collect licensing fees from entities (it could be an individual artist, a radio or TV station, a film production company, etc.) that want to use a member's music, and then redistribute the fees to said member as royalty payments. The process streamlines the use of, and payment for music in that neither party (the user or creator) need have anything to do with one another in order for the transaction to occur.
Both ASCAP and BMI have been widely criticized over the years on a variety of fronts. They have been particularly vilified by artists for the lack of transparency in the system they use to weight royalty payments. Additionally, they have been criticized for going after licensing fees in inappropriate situations, such as a 1996 incident in which ASCAP threatened the Boy Scouts of America and Girl Scouts of America with lawsuits for singing copyrighted songs at camp.