First, cold on the skin eases pain by slowing down the rate that pain sensors in the skin send pain messages to the brain. Second, the body responds to cold by closing down blood vessels in and under the skin. This decreases the amount of warm blood to the area.
A recent study of how tissues respond to cold packs demonstrated what happens when the cold pack is removed. The skin and upper layers start to warm up again, but the deeper tissues actually get colder. This is because the blood from the deeper tissues moves to the cold upper tissues to help rewarm them. The reduced blood flow from the deeper tissues causes a drop in temperature.