It goes like this:
In virtually every nation in the world, except the United States of America, each nation's government has its own bureau which collects royalties for songwriters and publishing companies, and disburses the funds to the songwriters and publishing companies (the "rights holders") after they withhold administrative costs.
However, in the USA, we do things by the private sector and capitalism. ASCAP and BMI are independent non-profit organizations who perform this function.
There is also a third performing rights company, SESAC, which operates in the USA. It is a privately held, for-profit company.
All three of these performing rights organizations collect royalties for songwriters and publishing companies regarding performances within the USA. These agencies also deal with the performing rights government bureaus of all the other nations of the world to collect royalties for American composers when their music is performed overseas, and for foreign composers whose works are performed in the USA.
There is a misapprehension that these performing rights organizations are "labor unions". They are not. They exist to collect royalties based on the USA and international laws.
ASCAP was started by music publishing companies, and was the first such company, and the only one for many years. BMI was created as a rival organization by the national association of radio stations in 1939 at a critical juncture when ASCAP wanted to raise the rates that radio stations had to pay to ASCAP to collect royalties for songwriters when they played their records. BMI started luring songwriters away from ASCAP with the promise of higher payments. For a short time, radio stations refused to play records of songs written by songwriters who registered with ASCAP. From 1939 to 1941 there was a huge struggle until the US government intervened and created a legal framework for both groups to coexist.
Today there is little functional difference between ASCAP and BMI. I'm told there was a time when a professional songwriter registered with ASCAP would refuse to co-write a song with another songwriter registered with BMI, because it made collecting any royalties on a co-written song much more difficult. But these days those barriers seem to have gone away.