A real estate broker is usually engaged by the seller of a particular parcel of real estate to find a buyer. The agreement between the broker and the seller is known as a "listing agreement". Although the terms of listing agreements may vary, its terms usually entitle the broker to a commission when he finds a "ready, willing, and able purchaser" of the concerned real estate. The listing agreement will usually specify the minimum terms upon which the seller is willing to sell the property, and the potential buyer must make an offer meeting these minimum terms in order to the broker to receive a commission. Once a potential buyer makes an offer to the seller meeting the minimum terms of the listing agreement, the broker is entitled to a commission even if the seller turns down the buyer's offer (in favor of a better offer, for example). Of course, the buyer must be in a financial position to pay the purchase price in order for the broker to be entitled to a commission.
In real life, though, it is not all that common for a buyer to make an offer that exactly meets the minimum terms contained in the listing agreement. Nevertheless, if the seller accepts the offer anyway, the broker is entitled to the commission. So although it is possible for the broker to be entitled to a commission even if the property is not sold, in practice this rarely happens - the broker's commission almost always comes as a consequence of the actual sale of the property.
In many cases the buyer's offer will be contingent - "I offer $100,000, but only if I can get a bank loan/sell my house/win the California Lottery". In this case the broker will not earn her commission until and unless the buyer gets his bank loan, sells his house, or wins the California Lottery.
DISCLAIMER: The following is intended for reference purposes only and not as legal advice.