Yes, real estate agents do not work for free. To be listed in the MLS, you must offer a commission to the agent who represents the buyer (AKA “cooperating broker” or “selling agent”). If a real estate agent presents an accepted offer and it goes to closing, you must pay the commission offered on the MLS listing. The commission is paid directly by you to the buyer's brokerage firm at the close of escrow.
If you sell your home to a buyer that is not represented by a broker or agent, then you pay no commission!