At New York City's Central Park Zoo, Marty the zebra (Chris Rock) is walking on a treadmill, daydreaming about running free in the wild. He swings on vines, jumps, does flips and runs through a bunch of singing penguins. Marty is jolted back to reality by his best friend, Alex the lion (Ben Stiller), who gets in his face and roars.Alex tells Marty that there's something in his teeth, so Marty tells him to open his mouth and let Dr. Marty, D.D.S., have a look. Marty reaches in and extracts a glass ball with a red ribbon on top. It's a snow globe, with a miniature Alex figure in the middle. It's a tenth birthday present for Marty from Alex. Marty puts the globe among a bunch of other "Alex" themed items that he'd been given over time. The gift did not excite him. In fact, he's bored and upset that his life at the zoo limits his ability to enjoy life more fully by keeping his movements restricted.Today was not only Marty's birthday, but "Field Trip Day" at the zoo, when all the school kids come. It was one of Alex's favorite days, and he excitedly woke up his other friends, Gloria the hippopotamus and Melman the giraffe, so they could get themselves ready. That's difficult for Melman, as he's a hypochondriac and worries about all sorts of ailments he thinks he may have.Alex quickly counsels Marty to work on changing his attitude, suggesting that he approach every day in a "fresh" way. So, Marty decides he's going to be "fresh" today.Mason the Chimpanzee (Conrad Vernon) starts his day off by rummaging through the waste can and coming up with a cup of coffee, bagel and newspaper, which he shares with his companion, Phil, another chimpanzee, who can't speak and just uses sign language.Once the gates to the zoo open, Gloria, Marty and Alex go into action, putting on an exhibition of dancing, posing, and doing acrobatics for the visiting people. They were very popular.There are four penguins at the zoo who are in the process of digging an escape tunnel. They are using plastic spoons and popsicle sticks to dig with, but their tools keep breaking and slowing them down.Marty is surprised when there's a small area of the grass in his compound that suddenly bulges upward, and the head of Skipper the penguin (Tom McGrath) appears, followed by those of his fellow penguins: Private (Christopher Knights), Kowalski (Chris Miller), and Rico. One of them asks what continent this is, and Marty says, "Manhattan." They realize that they've somewhat missed the mark, as their destination was the Antarctica, so they go back down to continue digging, but first swearing Marty to silence.Marty, Gloria, Melman and Alex all get V.I.P. treatments after the zoo closes, with the freshest of whatever foods they prefer, massages, and accupuncture. It's about as good as a life of confinement can be.Gloria's birthday gift to Marty is a cake, while Melman gives him a thermometer, not telling him it's his old rectal thermometer until Marty had put it in his mouth to try it out.Marty's birthday wish is to go to the wild. When Marty tells his skeptical friends that the penguins are trying to escape to the wild, Alex replies, "the penguins are psychotic." They engage in a discussion about where the nearest wild might be, and Gloria says she heard there are wild places in Connecticut.Alex tells Marty that there wouldn't be things like the fresh steaks he likes so much out in the wild. When Marty asks his friends if they aren't bothered by not knowing about the world outside the zoo, they simultaneously say, "no."Marty continues to be depressed, so Gloria makes Alex go and attempt to give him a pep talk. Alex knows that if he sings "New York, New York," that Marty won't be able to resist joining in, so he does that. Marty does join in, but the noise they make causes the other animals to start waking up and they shout out for Marty and Alex to "shut up."Marty tries to convince Alex to join him in breaking out and traveling north to Connecticut. Alex isn't interested, besides tomorrow is "Senior's Day," at the zoo and he doesn't want to miss that.Later that night, after the animals have all gotten back to sleep, Alex is wakened by Melman, who normally wakes up every two hours to pee. Melman tells Alex that Marty wasn't in his compound. Gloria comes over too, and they all wonder where Marty might be. Alex grabs a nearby phone and calls 911, before he realizes "we can't call the people."Marty is sauntering down a main street in downtown New York, headed for Grand Central Station. He stares at a woman walking by who is wearing a zebra striped outfit. He spends some time ice skating at an ice rink, then stops and talks to a police horse (David Cowgill), who gives him directions to Grand Central. The police officer (Stephen Apostolina), riding the horse calls into the precinct and asks if he can shoot the zebra. He is told no, that it's animal control's responsibility.Melman lifts Alex over the zoo wall and lowers him to the street. Gloria just busts through the brick wall, and Melman follows her out. Mason and Phil also go out through the hole in the wall. They all go to the nearest subway station and get in one of the cars, scaring and upsetting all the passengers. Before boarding the train, Melway goes into a restroom and comes out with one of those blue deodorizers in his mouth (he liked how it tasted).The animals ride the subway down to Grand Central Station, which is the same place Marty went. Wherever Alex goes, the humans all freak out and run, which he doesn't understand because he's not after them at all. There's an old lady (Elisa Gabrielli) who isn't afraid of him, and actually calls him a "bad kitty" and proceeds to start beating on him with her purse.When they find Marty, Alex rushes forward and tackles him, then hugs him, and finally chokes him, alternating in his emotions of concern, relief and anger. Marty tells Alex that he was going to come back to the zoo in the morning, after his little excursion to Connecticut.Hundreds of police show up and surround the animals. By then, the penguins and chimps have arrived and joined Marty, Alex, Gloria and Melman at the station. All the humans are on edge, and very afraid, especially of Alex. Except the old woman, who kicks Alex in the groin.Alex attempts to speak to the police and reason with them, but they don't understand him. So, he roars, in imitation of his popular daily zoo performance. The animal control officer is finally able to steady his nerves enough to shoot Alex in the butt with a tranquilizer dart. That puts Alex out. When Alex starts coming to, he's back at the zoo and there's an animal rights activist making a speech to a crowd about how the zoo animals should be returned to the wild. When they see Alex coming awake, they all get scared and run. Animal Control again responds by shooting at Alex with multiple darts. One of them hits him in the paw and he goes back to sleep.The next time Alex wakes up, he's in a wooden crate, as are Marty, Gloria, Melman, the penguins and the chimps. They are on a large ship that is sailing to Africa. The boxes that the animals are in are all labeled: "Kenyan Wildlife Preserve." Phil can read, so he signs that bit of information to Mason, who informs the rest of them.Rico coughs up a paper clip and uses it to pick the lock to the box holding the penguins. The four of them then waddle their way up to the bridge, disabling a crewman along the way, and administering a karate chop to the back of the neck of the captain of the ship, taking him out.Alex, Marty and Gloria all start arguing about their predicament and what they should do. Meanwhile, the penguins are on the bridge of the ship and struggling to figure out how to steer and navigate it. They more or less accidentally figure it out and Skipper orders hard right rudder. When the ship lurches, the crates holding Alex, Marty, Gloria and Melman, all fall overboard and are set adrift as the ship moves away.After traveling some distance, the crate holding Alex starts rolling and bouncing. It comes to a sudden stop and breaks open, sending Alex head over heels onto a sandy beach. He comes up coughing, with a mouthful of sand. He's all alone and spends a long time roaming the beach, calling out to his friends, and at one point, he even calls for Regis, Kelly, Matt, Katie, and Al.Suddenly, there's the sound of another voice and Alex looks up to see a crate with four legs sticking out of the bottom, running around the beach. It's Melman. Alex hurries over and attempts to free Melman from the crate. He pulls Melman's neck way out, but that doesn't work, so he grabs a coconut tree log and prepares to ram it into Melman's stomach to force him out of the crate. He steps way back, points the log, and starts running. Just before he slams into Melman, something distracts him and he stops short. Coming onto the beach through the surf is a large crate containing Gloria. Once the crate hits the beach, Gloria kicks one side of her crate out, freeing herself and at the same time sending Alex flying through the air and crashing down on top of Melman, smashing his crate and freeing him. There are two starfish and a crab covering Gloria's private parts, so she announces that "the party's over," and they all scatter.Marty is next to arrive, only he does so in style, riding onto the beach on the backs of some dolphins. Alex is surprised to see Marty, but in short order he realizes that all this grief he and the others are experiencing is because of Marty, so he starts chasing Marty around the beach, intending to beat him up. Melman and Gloria intervene and the four of them begin wondering just where they are. Melman looks around and offers his opinion that they are somewhere near San Diego, given the terrain and vegetation. Alex decides to chase Marty some more, because he doesn't want to be in San Diego where he likely won't be the star of the zoo anymore. Gloria stops Alex.Alex hears some sounds coming from deep in the jungle. It sounds like humans, so they all charge off towards the noise. Alex has trouble when he keeps running into things, including a large spider web, that causes him to fall behind. Meanwhile, Gloria, Melman and Marty come across a clearing that is filled with about a hundred lemurs of various sizes and ages. They don't recognize what sort of animals the lemurs are, just that they definitely aren't human. They watch the lemurs as they dance, sing and generally carry on. Melman tells the others that he's counted 27 health code violations taking place.A lemur named Maurice (Cedric the Entertainer) calls for quiet and introduces the lemur King Julien XIII (Sacha Baron Cohen). King Julien then launches into a rap song, "I Like to Move It." The lemurs are all enjoying themselves when suddenly an alarm is sounded and a lemur shouts that the fossa are coming. There are four fossa, which are animals that look like a cross between a cat and a dog, and prey on the lemurs. The lemurs all run, but the fossa catch a baby lemur named Mort (Andy Richter), and start making a salad, with Mort as the main ingredient.Alex finally catches up with his friends and as he gazes down on the scene before him, Gloria sees a large spider on his back. She picks up a stick, preparing to swat the spider. Before she can do that, the spider speaks, saying hello. That causes Alex to look and when he sees the spider, he freaks out, letting out a huge roar, which frightens the fossa and they run away, allowing the Mort lemur to escape. Meanwhile, Gloria starts hammering away at the spider on Alex's back, nearly beating him unconscious in the process.King Julien and his fellow lemurs don't know what to make of the strange animals who have suddenly appeared and scared the fossa away. He decides they must be aliens. To confirm whether the aliens are friendly or not, the king grabs Mort and tosses him towards them. Alex approaches Mort and attempts to make friends, but he's frightened of him and cries. Gloria picks up baby Mort and calms him down. The king now decides that these aliens are a bunch of pansies.King Julien, aka, "The Lord of the Lemurs," steps forward and says, "welcome giant pansies!" Alex decides that all the lemurs must be some sort of squirrels, because they act so weird. The king asks "where are you giants from?" and when Alex says, "New York," the king says, "All hail the New York Giants!"Alex asks the king about any people on the island, knowing that they need people to come find and rescue them. The king says there are people on the island, but they aren't very active. He then points up at a tree, where there's a skeleton hanging from a parachute. Not far away are the remnants of an airplane, also perched high in a tree. The king says there are no live people on the island.Alex loses it and takes off for the beach, intending to jump in the ocean and swim back to New York. Gloria again has to stop him and calm him down. She assures him that the people must be missing them and should be coming at any time to rescue them.Melman decides their situation is hopeless and he digs himself a grave there on the beach. Extending out from the grave is a long will and testament that he'd written in the sand. He starts to read it to the others, informing them of what he will leave to each of them, when a wave comes rolling in and erases the bottom third of the will. Melman says, "sorry Alex," as that portion of the will pertained to Alex's inheritance.Marty decides that he doesn't care if the humans come to find and rescue them, because he loves his newfound freedom there in the wild. That upsets Alex and he takes that large coconut log and draws a line in the sand, telling Marty that he must stay on the other side of that line, while Alex and the others, who want to be rescued, will stay on the opposite side. That doesn't bother Marty, as he immediately sets about building himself a little beachside patio, complete with a large umbrella, fire pit, bar and lounge seats.Alex starts building something too. It ends up being a large figure, similar to the Statue of Liberty, and he calls it the "Beacon of Liberty." His intent is to set it ablaze once they see a ship out on the ocean, so the people will see it and come to their rescue. While Marty has already started a little fire in his fire pit, Alex has ordered Melman to work on starting a fire for them. Melman is getting very tired rubbing two sticks together, trying to create a spark. However, he eventually does get some sparks, then flames, but the flames catch the sticks on fire and Melman becomes frightened and starts running around. He accidentally sets the Beacon of Liberty on fire and it quickly burns down. Alex can't believe it.Back at the lemurs place, the king is telling his fellow lemurs that he wants to make the New York Giants their friends, especially Alex, who would then keep the fossa away from them. Maurice then poses a question to them all, asking them to consider why it is the fossa are afraid of Alex, and perhaps the lemurs should be afraid of him too. No one seems particularly concerned.Back on the beach, Alex has built another structure, made of coconut logs. This one spells out the word, "HELP."Melman and Gloria decide to join Marty on the "fun side" of the island, and are over sitting under the umbrella, near the fire pit. Marty invites Alex to join them, telling him that it's not really the fun side without him there. Marty continues to refuse. As he sits there pouting, the "P" in his help sign collapses.After some time, Alex decides to go over to the fun side, apologizing to Marty and asking to join the others. Marty welcomes him to "Casa del Wild," and prepares Alex a drink, which he serves to him in a coconut shell. Alex takes a big gulp and immediately spits it out. Marty has to explain that the drinks are just sea water, but that's only until the plumbing is fixed. Gloria, Melman, Marty and Alex then continue sipping their drinks and spitting it out.Marty then prepares something he calls "seaweed on a stick," and offers some up to his friends. Gloria and Melman think it's very tasty, but Alex starts choking when he eats it. He is very hungry for meat, and misses the steaks he used to eat at the zoo in New York. After he falls asleep, he dreams about steak, and he starts to lick one. He is jolted awake by the others and finds himself licking Marty's backside. Marty wants to know what Alex thinks he's doing. Alex pretends to have been counting Marty's stripes.Meanwhile, 2,500 miles to the south, the penguins have arrived at their dream destination, Antarctica, and are standing quietly on the ice, near the bow of the ship. The wind is blowing and there's nothing around them except ice and snow as far as the eye can see. Finally, Private turns to the others and says, "well, this sucks."King Julien and all the lemurs make noise and wake up Alex and the others, surprising them by leading them to an overlook where they gaze out upon a huge expanse of open area, with beautiful green grass, trees and waterfalls visible way in the distance. The king says, "Welcome to Madagascar."It all looks just like the poster that Marty had on the wall back in New York. It was just like the land in his dreams. He and Alex rush forward and romp through the grass, wrestling and teasing each other as they went. Alex tires temporarily, as he hadn't eaten for a long time, but rediscovers that he has more energy than ever and continues his romp.Marty suggests to Alex that he perform his zoo routine for the lemurs. When Julien hears Alex refer to himself as a "king," he becomes concerned, thinking that there can't be two kings on Madagascar.The fossa arrive and observe Alex's performance from behind some rocks. As Alex continues his performance, he looks out over the crowd, comprised of the lemurs and his friends, and they all start to look like steaks to him. When Alex lets out a huge roar, the fossa run off and everyone else decides to run as well, because Alex is attacking. When Alex snaps out of his hunger induced temporary insanity, he has his jaws attached to Marty's butt, but he hadn't bitten down yet.Maurice takes advantage of the moment to educate everyone about the fact that Alex is an apex predator, and if he's hungry, no one is safe. About that time, Alex sees steaks again and starts another attack. He always seems to hone in on Marty as his target of choice. Alex is about to pounce on Marty when Maurice fires a coconut from atop a tree and beans Alex with it, saving Marty.Alex recovers and is very upset at himself for attacking Marty. He's worried what might happen, so he runs off. He falls into a river and ends up floating to another part of the island, the place where the fossa live. There, he sharpens a bunch of sticks and inserts them into the ground, sharp sides up. He's created a sort of jail for himself, with the sticks at the base of some rocks and himself sitting on the rocks.Marty, Gloria and Melman also find themselves roaming around in the land of the predators, where the fossa live. As they walk, they observe several small animals get eaten up by much larger predators, and they are not at all comfortable.A boat horn sounds out on the ocean, so Marty, Gloria and Melman hurry to the beach. They see the same ship that they'd been on earlier. Melman struggles to hoist Gloria up high on his head, his neck bending severely as he does it, but her waving seems to work, as the ship begins to turn around and head for the island. Marty decides to hurry and go find Alex, but Gloria stops him, knowing he wouldn't last long in the land of the predators.The ship arrives at the island and the bow comes right up onto the beach, flush against Melman's face, as he's standing there in shocked amazement. The anchor drops onto the beach and the four penguins appear. Gloria asks them where the people from the ship are and Skipper tells her that they "are on a slow lifeboat to China."During the distraction of the ship coming aground on the island, Marty has run off to go find Alex. He finds him sitting in his little jail enclosure. Alex talks to Marty for a little bit, then lunges and takes a swipe at him. He couldn't help it, he was so hungry. He regains his senses and goes deeper into the rocks to hide. Marty follows him partway and tells Alex he isn't going anywhere without him. He starts to sing, "New York, New York." Alex doesn't respond.The fossa have arrived and are gathering around Marty in force. Soon, they attack and Marty has to run, calling for help. Just as it appears Marty is doomed, Melman and Gloria arrive. Melman sweeps down from on high and scoops up Marty, carrying him to safety. The penguins are there too, and Skipper steps forward, producing a flare gun which he fires into the air, distracting the fossa. He and the other penguins then quickly rig up a device using the steering wheel from the ship, and spin it around rapidly, striking the attacking fossa and knocking them unconscious.Alex shows up, roaring and showing his teeth. He makes as though he's attacking Marty, claiming Marty as his territory, as his meal. Marty is about to faint, thinking Alex is really going to eat him, until Alex whispers to him that it's all for show.Alex then grabs Marty, Gloria and Melman and hoists them all above his head, proclaiming to the fossa that they all belong to him. Then he sets the three back on the ground and starts taking it directly to the fossa, knocking them this way and that, until they all decide to run off. He shouts at them to never come back.The king observes all this and becomes very happy that his plan had worked out after all.Back on the beach, Rico is working feverishly as a chef, preparing some sushi, which is then fed to Alex. Alex is tentative, but he tries it and decides he likes it. He orders 300 pieces to go.Everyone enjoys themselves at the "Thank You Freaks," banquet put on by the lemurs. There's a massive toast, with everyone taking a drink from their coconut cups and then simultaneously spitting it right back out.Marty tells his friends that he's ok with just staying on Madagascar, or going back to New York, just as long as he can be with his friends. They decide to go back to New York.The king gives Alex his crown, then produces a new one for himself. His new crown is larger and has a live gecko on it.Marty, Alex, Gloria, and Melman board the ship. The chimps are still there too. The ship is loaded with lots of fresh fruit and sushi, ready to sail. Alex envisions them making some side trips, since it will be winter at the New York zoo. The penguins, however, are all sitting in beach chairs, sunning themselves. One of them wonders if they should tell those on the ship that it's out of gas.
Output: Question: Why does Alex attack Marty?, Answer: he was so hungry.