The broker is paid by whoever has promised to pay. In most cases, that's the seller of the property. Some buyers hire their own agents, usually with a promise to pay that broker if it turns out the seller has not offered a share of commission to whichever agent brings the buyer.
You mention "paying a realator". Only a licensed broker can collect commissions. An agent who is licensed as a salesperson is working more or less as an apprentice under the supervision of a broker who will collect whatever fees are due on a transaction. A Realtor is a broker who chooses to join a private trade organization known as the National Association of Realtors.