Chlorine kills most pathogens very quickly at very low levels of active chlorine (hypochlorous acid) and it is also an oxidizer so can get rid of nitrogenous bather waste. The reason chlorine is so effective is that the molecule looks a lot like water. See hypochlorous acid:

and compare this to water:

Both molecules are polar, small, and neutral in charge. Once inside a bacteria, algae, or other cell the chlorine atom attached to hypochlorous acid can react with nitrogenous chemicals including some amino acids, proteins, and DNA and in some cases oxidizes or partially oxidizes these chemicals. This disrupts chemical processes in the cell preventing the cell from reproducing.

The water in a swimming pool may be contaminated with bacteria from the source. Also as we go swimming in it, bacteria (especially a species called Escherichia coli) from our bodies escape into it. Chlorinating the water kills these bacteria.

how does this work?

Chlorination can be done in two ways. In the first, liquefied chlorine gas is added directly to the water. It dissolves to form hydrochloric acid and hypochloric acid. In the second method, sodium hypochlorite salt is dissolved in water.

In both cases, a hypochlorite ion is produced, which breaks up under the effect of sunlight to release oxygen free radicals. The oxygen free radical reacts with all organic matter it encounters, killing the bacteria present in water. Some chlorine molecules that fail to ionize in water also react with organic matter.

is this effective?

Chlorine (gas) is known to kill almost all kinds of bacteria, as well as viruses and protozoa. It is most effective when added at night. This is because it gets more time to act; in bright sunlight the hypochlorite ion breaks up very quickly. Also, it leaves behind no contaminants in the water, except the harmless chloride ion. Finally, it is an affordable method, especially for a huge volume of water like a swimming pool.