Here's an example of an anime that didn't exactly follow the manga: Negima!.
This story, about a ten-year old mage, is assigned as his "residency" (for lack of a better term), to be a middle school teacher in a junior-high in Japan. He's from Wales. The story follows the manga fairly closely for a good length of the anime, but then goes off the rails. Why? Because the series was so popular, and production was rushed to keep up with demand, the animation team ran out of source material and had to improvise. Many fans became upset by this, and deemed the anime as trash.
Another example is Excel Saga. The Mangaka explicitly demanded the anime to not follow the manga. In fact, he insisted the studio use its Creative Liberty into maximum overdrive. The result, was a spectacularly unhinged and humorous anime that's loved by weird people, like myself!
Sometimes the story must be altered because the receiving fan-base isn't prepared for it. Case in point: Sailor Moon. When Sailor Moon aired in the United States back in the 90s, most people considered any animated medium to be for children, despite some of the quite adult-natured themes present within the story of Sailor Moon. (I haven't had an opportunity to read the original Japanese manga, but based on word from others who have, it's quite risque at times.) In this case, I believe that initially the alterations did the original story a beneficial service, because without those changes, anime (at least Sailor Moon) would have been relegated to the depths of pornography and never would have been given the exposure needed for our love of the hobby we have today that we enjoy.