Your muscles have electrical signals moving through them when they are working, but not when they are resting. Trained doctors can look at the electrical signals in your muscles to help diagnose conditions.
During the EMG, you might have the needle or needles put in different parts of your body so the doctor can do a thorough test. The needles might be painful for a bit, but the soreness will fade after a few days.