1 - Before getting off the bike, downshift to the smallest front chainring. Being positioned on the smallest front chainring means that the chain is placed on the largest toothed wheel. Keep pedaling. This simple step should allow the chain to realign itself.
2 - If step 1 didn't work, get off the bike and lift the rear tire while rotating the pedals with your hand.
3 - If step 2 is not enough, push the rear derailleur forward to release the tension on the chain. Lift the chain and place it back on the tray. Turn the pedals with your hand while lifting the rear wheel to realign the chain (as in step five).
Bike chains are very oily and you will get your hands dirty. Use a pair of mechanic's gloves or use a twig or leaf. This step may take several attempts, but will eventually par function.