The asking price is just a figure, sometimes made up. You can offer more or less than that. In your case, someone offered more.
There's no right to make a counter-offer. You made your offer. Another buyer made his offer. The seller accepted the other offer. If the seller had chosen to, he could have asked you to make another one . . . but that's totally at the seller's option.
How'd the other buyer know to offer $500 more. Simple (and it's no deep conspiracy, either). The other buyer saw that the asking price was a good one. He figured someone might offer full asking price (as you did). To top those offers, he offered a bit more. And $500 is enough to make a difference without wildly overspending.
You're also accusing your agent of "purchasing the property out from under us." Did she actually buy the property? You don't say so; you suggest it was someone else. Anyone was free to come along and make an offer.
You made a $6,000 deposit. Fine. It's possible the other buyer made a larger deposit, in addition to making a slightly higher offer.
I don't really see (from your question) that you were unfairly or improperly treated. You simply got outbid on a property.