This has been common knowledge for as long as the theory of evolution has been around, but only recently have scientists been able to identify a link between whales and their land ancestry. That all changed in 2007 when researchers discovered the 48-million-year-old skeleton of a creature called Indohyus.
The bones of this tiny deer-like mammal have a thick outer layer, which is typically characteristic of slower aquatic animals such as our modern hippopotamus. This combined with the fact that its teeth also contain similar oxygen isotope ratios indicates that Indohyus must have spent much its time in water.
This seems bizarre, but that is often the way in which evolution works. Over the years, environmental factors such as predators likely forced Indohyuses to spend more and more time in the water. The Indohyuses that were the most skilled at swimming were the most likely to evade capture and survive, so this trait eventually was more and more common in subsequent generations. Over millions of years, this adaptation became so dramatic and environmentally essential that now our modern whale spends ALL its time in the water! (this is a very simplistic explanation of evolution, but you get the idea)
Here's a video depicting this idea. The African mousedeer, or chevrotain, has been known to escape predators by taking to the water (it is not closely related to whales, however):