The end-Cretaceous mass extinction knocked off not only the dinosaurs (except for birds), but also air-breathing marine predators like mososaurs and plesiosaurs. Birds and mammals started moving into the empty niche: penguins from early on, and eventually whales.
(Cartoon by Sam Gross. Not scientifically accurate.)
People around the world seem to be naturally inclined to distinguish major animal life forms according to whether they walk, fly, swim, slither, or creep, so evolutionary shifts in modes of travel – the origin of flight, the return to the sea – really catch people’s imagination – and provoke Creationists. The whale story is particularly dramatic. When Darwin was tried to account for the evolution of whales from a land-dwelling ancestor, he cited accounts of bears swimming and feeding in water, and wrote “I can see no difficulty in a race of bears being rendered, by natural selection, more and more aquatic in their structure and habits, with larger and larger mouths, till a creature was produced as monstrous as a whale.” This statement attracted so much ridicule that Darwin took it out of later editions of The Origin of Species. But he turns out to have been very much on target. We now have a great sequence of whale ancestors. The sequence runs from today’s Pakicetus — a wolf size meat-and-fish eater that splashed along the shores of the ancient Tethys sea separating Africa from Eurasia — to the “walking whale,” Ambulocetus, and on to true whales. Darwin was sort of on the right track thinking of bears, but anatomy and genetics put the ancestors of whales firmly among artiodactyls – hooved animals including hippos, pigs, and cows.