How potassium iodide pills can help in a nuclear emergency

People that live, work or study close to a nuclear power stations are often asked to take potassium iodide pills in the event that radiation is accidentally released. So how do they work?