It can get quite messy if the the agent who showed you the property is what is known as the "procuring cause" of the sale. Procuring cause means the agent who showed you the property was a "big reason" for you becoming involved with that property. For example, he sent you the listing. Or you were aware of the property through his efforts. If that is the case, he is entitled to at least a portion of, if not all, the commission. It's only fair in that case, correct?
On the other hand, if you were already working with an agent and just happened to stroll through an open house, the situation can get a bit tense. But usually the brokers of the firms involved can arrive at an amicable solution that usually involves some kind of split.
The bottom line is the concept of "procuring cause". Here is a link with more information: