One additional viewpoint: I have a three year old who sometimes is similar (also with his younger brother), and one piece of advice I've been given that I think rings true: if he's having trouble sharing or playing with others, it may be a cry for more time or space of his own.
This is both time and space literally on his own - toys that he does not have to share, an area other kids can't go to, etc. - or more one on one time with his parents.
One thing they're dealing with at two is the concern that their toys may go away. Having some toys that are consistently their own, guaranteed not to be taken away or have to be shared, can encourage sharing further as the child feels more safe and secure with what he has. If you're going to a playgroup, bring a toy or two designated as your son's. Tell him he has to share the toys that are common (either ones you bring or are at the location you go to), but these couple of toys are just his and are not for sharing.
As far as space, it's very stressful having other children near to you at that age. You have to practice constantly behaving well, sharing, figure out how to navigate uncharted social waters, etc., and are constantly evaluated; imagine at work if you constantly had to do new things and had your boss literally watching over your shoulder, plus a bunch of your colleagues constantly trying to take your laptop away. Having some space he can retreat to is very helpful. This isn't always possible at daycare or whatnot, but if you're there and see him getting stressed, take him away from the situation and to a consistent, calm location where he can work out his anxiety.
And then, of course, more mommy or daddy time is very helpful sometimes. Knowing he's safe and secure with you can do wonders for social development. Not that he has to spend all of his time with you of course - but it may be that he needs a little more, or maybe just in these instances when he's getting stressed out.
In general, when he's having trouble, don't treat it as a situation to be punished; treat it as a chance for you to help him. So much of this difficulty is just working out his place in life and how to interact with others. Sometimes that learning is hard, and he needs a little extra time to figure things out, but he will - though it will take several years to work a lot of these issues out. That's perfectly okay. I'd rather have a rambunctious, self confident and self assured son than a child that lets others run over him: self confidence is a lot harder to teach than self control, from my experience.