I have a 2000 Hyundai Sonata with 70000 miles on it. Last night when I started it to go to the store, it idled smoothly, but got rough when I put it in gear. I figured it was just cold, being about 20 degrees outside. A block later the check engine light came on and stayed on until I got to the store and put it in Park. Then it idled smoothly. On the way home the same scenario. It was running like it had water in the fuel, kind of hitting and missing, but would respond if you hit the throttle.
The check engine light is most likely on for a mis-fire fault according to your description. The fault may be due to several factors(coil issue, sparkplug issue, wiring issue, or bad fuel)and I recommend you scedule an appointment with your Hyundai service provider straightaway.