The system detects the steering wheel angle, speed of each tire, yaw and direction of the car and can activate the brake on one or more wheels as appropriate to help prevent a skid.
In a typical event in which ESP comes into play, the driver decides that the vehicle is slightly too fast and wide in a corner, and so applies more steering lock. The front tyres, which are already heavily loaded laterally, supply a little more lateral force, but not enough for the driver, so he adds more steering lock. The ESP monitors the steering wheel angle and the vehicle's yaw velocity, and when the error between the two exceeds pre-programmed limits, it intervenes, and brakes the inner rear wheel (typically). This tends to cause the rear axle to slide outwards, hence pointing the nose of the car tighter into the corner, which is what the driver wanted to do.