Counter offers come when you inform your employer you are leaving. Don't take them, recommend career experts Valerie Fontaine and Roberta Kass.
Employers make counter offers primarily because they don't want to be the one fired and also they probably need time to scout up a replacement for you. Yes, in some cases, your skills are unique. The employer perceives you as vital to the operation and will pull out all stops to keep you.