Wow some of you are really showing your age by the wonderment at how this could possibly happen while dancing.
If you go to any party in the present day frequented by late teenagers to early twenties, the music will probably be some form of dance, house, or hip-hop. The style of dancing will be grinding, or as a casual observer would describe it - dry humping.
An entirely plausible scenario:
Off-duty officer is bent over at the waist, angling the barrel of his gun 90 degrees to the rear. The woman "hugs" him by grabbing his hips, placing one of her digits over and in the trigger guard through a cheap nylon holster. A little gyrating and the gun goes off. Traditionally the male and female roles are reversed in this position, but stranger things have happened.
Combine a relatively tall man, a relatively short woman, a forward cant on the holster, and probably more than a little bit of shifting and you have a heart shot.
If police departments issue holsters for off duty carry, they are usually the cheapest crap they can get. If the department does not issue holsters, many officers are cheap, and will buy that same crap.