It's been known for a long time that, at the highest level, mammals can be divided into three evolutionary groups based on their method of giving birth: marsupials, the egg-laying monotremes, and the placental mammals. That last group contains around 95% of all living mammal species, including everything from wolves to dolphins and moose to monkeys.
Given that wide variety, it's less obvious how we should divide up the placental mammals into smaller groups that genuinely reflect their evolutionary relationships. It's obvious that, say, cheetahs are members of the cat family and, at a slightly higher level, it's unsurprising that, for example, the dog and bear families are reasonably close relatives of one another. But once you get much higher than that, it becomes less so.
Back when I was first studying zoology in the 1980s, I was taught that the placental mammals could be grouped into a number of "cohorts" based on their evolutionary relationships. How the various cohorts related to each other was less obvious, but the animals within them had enough anatomical similarities that we could say, based on what we knew at the time, that they were likely to be real groups.
Take, for example, the ungulate cohort. The term "ungulates", as originally conceived, means "hoofed animals" although in a more scientific sense, it would include a number of mammals that don't literally have hooves, but are related to those that do - such as, say, camels. They tend to be relatively large animals and the great majority are herbivorous, with just a few omnivores.
At the time, there were thought to be three general kinds of ungulate. First were the "sub-ungulates", animals that weren't part of the true hoofed group, but did have some similarities - the most obvious example being the elephants, which certainly qualify as large herbivores. The ungulates proper fell into the remaining two groups, first identified as such by Richard Owen (more famous for coming up with the word "dinosaur") in 1848.
The first of these groups are the perissodactyls, or "odd-toed ungulates", which put most of their weight on the third toe of each foot. (Or what would have been the third toe, if they still had the full five that their original ancestors had). There are just three living families of perissodactyl, none of which have a particularly large number of species: the horses, rhinos, and tapirs. As it happens, tapirs have four toes on each of their front feet, but otherwise the feet of living examples of these kinds of animals always have either three toes or just one - an "odd" number.
The artiodactyls, or "even-toed" ungulates, are a much larger group. They place an equal amount of their weight on the third and fourth toes and, in most cases, the others have been reduced or even lost, producing the classic "cloven hoof". Most artiodactyls are also ruminants, with four-chambered stomachs that enable them to more efficiently digest tough vegetation; in contrast, perissodactyls tend to be hind-gut fermenters, performing the same action in an enlarged part of the colon.
While it's hard to evaluate the structure of a stomach when all you have is a fossilised skeleton, the pattern of evolution within the artiodactyls nonetheless seemed pretty clear. At the "bottom" of the tree, having changed the least since the time of their original ancestors, were the entirely non-ruminant artiodactyls, such as pigs. At some point, a group branched off, developed a three-chambered, ruminating stomach, as we see today in camels, and then some of those added a fourth chamber for greater efficiency and (in most cases) developed head ornamentation while they were at it. This last group was the most successful, including cows, sheep, goats, lots and lots of antelopes, all the deer, and a few other cloven-hoofed animals, such as giraffes.
This is all very neat, makes a lot of sense and is... well, not entirely correct.
In the 1990s, methods for examining the genetics and biochemistry of animals became much cheaper and more practical. This made it possible to get around the problem of parallel evolution, where two animals come to look similar because they're trying to do broadly the same thing. This is not to say that we couldn't get parallel evolution in, say, blood chemistry as well, but if the animal isn't doing anything that would require unusual blood (surviving at high altitude or holding their breath for hours on end while they dive, for example) there's no obvious reason why it should do. Moreover, if you check enough different proteins and genes and do so in a number of different ways, and they all come back with the same answer... you're probably on to something.
This kind of study revealed, in a relatively short period of time, three surprising things about the ungulate family tree. These have all been confirmed by multiple studies over the last few decades, and can, at least in general terms, be reasonably regarded as settled.
Perhaps the least surprising discovery was that the subungulates aren't all that closely related to the true ungulates at all. In retrospect, there had been some hints about this for a while, but by 1998, it was clear that the subungulates belonged to an entirely different branch of the mammalian tree than the true ungulates did, having first evolved in Africa long before that continent collided with the northern ones where the true ungulates had been evolving. As a result, the term "subungulate" has tended to fall out of use, since it implies that they were a lower step on the evolutionary ladder, which they clearly aren't; alternatives such as "paenungulate" (literally "almost hoofed") are usually preferred.
On the other hand, it certainly does seem to be the case that the perissodactyls and artiodactyls are each other's closest relatives. Some alternative schemes were proposed early on, but these have largely been overturned by more complete studies since that time.
The second surprise is that pigs turn out to be more closely related to animals such as deer and antelope than they are to camels. Since it's hard to imagine that the common ancestor of all these creatures had a multi-chambered stomach and that the pigs subsequently lost it, the most obvious conclusion is that this, too, is a case of parallel evolution. Camels evolved their three-chambered stomach separately from the other ruminants developing their four-chambered one - a similar solution to the same digestive problem and not, as it turns out, an intermediate step on the path to greater efficiency.
(You knew I was going to get around to them eventually, right?)
I don't mean by this that whales are the closest relatives of ungulates, or even of one of the two ungulate orders as had previously been proposed, partly on the basis of what very early whale fossils looked like. Instead, they are, in fact, a branch within the artiodactyl family tree, diverging from the line that led to antelopes and so on after the camels did, and possibly also the pigs.
In terms of taxonomy, this can mean one of two things: either the artiodactyls don't really exist as an evolutionary group or whales and dolphins are themselves a kind of artiodactyl. The latter has become universally the preferred option, although there has been a recent move towards changing the name of the group to 'Cetartiodactyla'. Technically, there's no reason why anyone should do that, but I guess some people feel uncomfortable with keeping the older name.
At first, this idea was met with a fair degree of resistance, especially among those who worked primarily with fossils where any molecular data simply doesn't exist, forcing us to rely on physical resemblances alone. However, the evidence really has rolled in, and is no longer in real doubt.
So, whales and dolphins are artiodactyls, highly evolved and modified versions of cloven-footed animals. But since they are just one branch among many in that group (albeit one with a particularly large number of species) it follows that some of these large herbivores are more closely related to them than others. So, to answer the question in the post title... which ones?
To cut a long story short: hippopotamuses. These had previously been thought to be related to pigs, and they sort of are, but it turns out that they are closer still to dolphins, porpoises, blue whales and all the rest. Which, as large, semi-aquatic, almost hairless animals does make this sound a little less strange than it otherwise might.
[Photo by Robert Pittman of NOAA. In the public domain. Cladogram adapted from Upham et al. 2019.]