At the Central Park Zoo, Marty the zebra is celebrating his tenth birthday, but has grown bored with his daily routine and longs to experience the wild. Marty’s best friend is Alex the lion, who enjoys showing off for the public and his celebrity status as “the king of New York”. Alex attempts to cheer Marty up, but Marty, still unsatisfied, gets some tips from the zoo’s penguins—Skipper, Kowalski, Rico, and Private—who are trying to escape the zoo, and follows them out. Alex, Melman the giraffe, and Gloria the hippopotamus pursue Marty in an attempt to convince him to return. The four, along with the penguins and two chimpanzees named Mason and Phil, find themselves at Grand Central Station, where they are quickly sedated via tranquillizer gun when Alex’s attempt to communicate with humans is mistaken for aggression. The zoo, under pressure from anti-captivity activists, is forced to ship the escaped animals by sea to a Kenyan wildlife preserve. During their travels, the penguins escape from their enclosure and take over the ship, intent on taking it to Antarctica. Their antics on the bridge cause the crates containing Alex, Marty, Melman, and Gloria to fall overboard and wash ashore on Madagascar.
The animals are soon able to regroup, initially believing themselves to be at the San Diego Zoo. Upon exploring, however, they come across a pack of lemurs, led by King Julien XIII, and learn their true location. Alex blames Marty for their predicament and attempts to signal for help to get back to civilization. Marty, on the other hand, finds the wild to be exactly what he was looking for, with Gloria and Melman soon joining him in enjoying the island. Alex eventually comes around, but, being separated from the raw steaks he was provided at the zoo, his prey drive begins to show as hunger kicks in. The group is accepted by the lemurs, though King Julien’s adviser, Maurice, cautions them about Alex’s predatory nature. King Julien ignores Maurice’s concerns and persuades the group to help the lemurs fend off the fossa, who hunt the lemurs as prey. While Alex initially scares the fossa away and is worshiped by the lemurs, later, compelled by hunger, he attacks Marty. Realizing that Alex is now a threat, King Julien banishes him to the far side of the island where the fossa live. Seeing what has happened to Alex, and how how difficult it is to survive with so many predators around the island, Marty begins to regret his decision to leave the zoo.