In short, it controls the brakes on an equipped trailer in such a manner as to promote maximum control while braking.
Most nice controllers use accelerometers to sense acceleration or deceleration in addition to having a wire jumped in from the brake switch. This allows them to adjust trailer brake pressure to match the tow vehicle brake pressure. The harder you hit the brakes, the harder the trailer brakes hit.
The most basic brake controller applies the trailer brakes at a fixed rate whenever the tow vehicle's brakes are hit. They usually have a ramp time, a time in which the brakes are applied, this is usually less than 3 seconds. This prevents heavy jerking that could occur if the trailer brakes were applied before the vehicle brakes.