The movie starts in the past, in an African reserve, when Alekai the Lion was just a little cub, being tutored in the art of being a lion, by his doting father, Zuba (the late Bernie Mac), who is also the Alpha Lion. Alekai is full of life and more interested in playing the fool, by dancing around and doing the "happy face/angry face" gag with his paw. Zuba shows him his paw, which has an Africa-shaped birthmark on it, which Alekai also has on his paw. Just then, Makunga (Alec Baldwin), a scheming lion who wants to be Alpha Lion, challenges Zuba. Leaving Alekai alone for a while, Zuba kicks the pride out of Makunga. As the fight is going on, Alekai notices a piece of rope moving on the ground and follows it. He goes off the reserve and is captured by poachers, who dump him in a crate and put him in the bed of their truck. Zuba, having cleaned Makunga's clock, notices that his son is missing. He sees the truck moving along the fence of the reserve and hears his son, crying out for help. He runs and jumps on the truck. He manages to free the crate of its binds, when one of the poachers shoots him, causing him to fall off the truck. He doesn't notice that Alekai's crate has fallen out of the truck-bed and into a nearby river. Despite the painful hole in his ear, he mourns the loss of his son.
Meanwhile, in the box, Alekai sits timidly. Finally, he reaches New York City (pre-2001) and is fished out and put in the New York City Zoo. When he sees all the people looking at him, he starts to dance around, much to the audience's pleasure. As he vamps for the people, behind him, a young Marty the Zebra tells a young Gloria (the Hippo) and Melman (the Giraffe) that Alekai's a show-off. Years later, Alekai is now Alex the Lion (Ben Stiller) and is still a huge hit with the zoo spectators. Marty (Chris Rock) tells Gloria (Jada Pinkett Smith) and Melman (David Schwimmer) that he still thinks he's a show-off.
Then, we see a TV news report on the four animals' NY escapade (from the previous movie) and their encounter with the fearsome Nana (Elisa Gabrielli). After they were recaptured, animal rights activists demanded that they be sent back to the wild. During their voyage, their ship went missing, much to the sadness of New Yorkers.
Next, in the island of Madagascar, we see that the four animals are now preparing to go back home, thanks to the airplane that the penguins supposedly fixed. As they climb up to the huge platform that the lemurs built, they groove to the tune of "I like to move it". They exchange warm goodbyes to the lemurs, at least most of them. King Julien (Sacha Baron Cohen), dressed as a lady in a cake, and Maurice (Cedric the Entertainer) are coming along. When the creepy little Mort tries to come along, Julien turns security loose on him and herds everyone into the plane. The two monkeys are also there.
With the lemurs' help, the plane is catapulted into the air. As they fly, Alex sees Mort on the wing of the plane (a la "Nightmare at 20000 Feet"). However, when Mort waves at him, he loses his grip and falls off. Inside the plane, the animals talk about Madagascar. Gloria mentions that, when they reach NY, she might get into the breeding program, which makes Melman a bit jealous. In the front of the cabin, Julien and Maurice sit in "first-class", eating shrimp.
Soon, the plane runs out of fuel and starts to crash-land. As they crash, Alex and Marty say their heartfelt goodbyes, while Melman loudly professes his love to a sleeping Gloria. Julien and Maurice are sucked out of the plane, but parachute down safely. However, thanks to the penguins, they manage to crash-land safely, though the plane is wrecked. When the dust settles, they look around, wondering where they are. The penguins tell the animals that they will need time to work on the plane and will need the monkeys' help.
The four animals wander off. Suddenly, a jeep approaches, filled with tourists who click pictures, and drives off. Alex runs after the jeep, trying to get help, but is attacked by Nana (who's on the jeep). After a brief, comical fight with her, he ends up on the losing side. The jeep drives off, but Alex got her handbag. He takes her cell phone and is about to call someone, when they look down the cliff they're on and see several animals - hippos, lions, zebras and giraffes, among others. They realize they're in Africa (not the San Diego Zoo, as Melman suggests).
They go to the watering hole, where the animals are assembled. Alex tries to make contact with the natives. They ask how the four of them got into the reserve. At that moment, the Alpha Lion, Zuba, and his mate (Sherri Shepherd) approach. Zuba doesn't recognize Alex, though Alex feels he's seen Zuba before. Suddenly, Zuba's mate recognizes Alex and looks at his paw, with the Africa-shaped birthmark on it. Zuba and Alex's Mom are overjoyed at the return of their son, as is Alex at being reunited with his parents. All the animals around rejoice the return of Alex, the "King of New York". And, surprisingly, so does Makunga. He is going to use Alex against Zuba, to become Alpha Lion. Julien and Maurice show up and partake in the celebrations, thinking it's for them.
Marty meets the other zebras (who all sound exactly like him). They welcome him into their fold. Gloria meets the other hippos and becomes the object of attraction for Moto Moto (Will.i.Am), the hippo "hunk". Melman meets the giraffes and asks about medications. They say that now that their giraffe-witchdoctor Joe is dead, if any giraffe gets sick, they go into a hole and wait for death. Horrified, Melman volunteers to become the giraffe-witchdoctor.
Makunga speaks to Zuba about banishing Alex as he has not performed the rite of passage that all young lion cubs should perform. Alex, thinking it to be a breeze, accepts. Meanwhile, Marty finds out that his "water-spit" trick is no longer exclusive to him, as all the other zebras learn it immediately. He is surprised to see that all zebras are exactly like him. Melman, after having helped out a young giraffe with a broken leg, is informed that the brown spot on his neck is a symptom of Witchdoctor's disease and he has 48 hours to live.
Meanwhile, the penguins hijack safari jeeps to use to fix the plane, rendering many of the tourists (including Nana) stranded in the African reserve. The monkeys bring a whole bunch of monkeys as extra help for fixing the plane. Nana (having just gotten her beloved handbag back) leads the stranded tourists, who are all from New York, and tells them that, as New Yorkers, they can survive anything.
Alex prepares for the rite of passage, thinking it to be a dance-off. As he prepares, Makunga comes along and talks him into choosing Teetsi, who Alex thinks will be his dance partner. When the time comes for the rite of passage, Alex does indeed choose Teetsi, who turns out to be something like the Incredible Lion Hulk. Alex still thinks it's a dance-off and dances around, to the confusion of his father, until Teetsi levels Alex with a punch. Now that Alex has been defeated, Makunga says that Alex should be banished. Unable to do it himself, Zuba tosses away the Alpha Lion scepter and abdicates. Makunga obligingly decides to become Alpha Lion. Alex is made to wear a ridiculous fruit hat, as his punishment.
Zuba berates his son for shaming him. Alex walks off in a huff. In the wreckage of the plane, Alex, Marty and Melman sit, mopily. Alex is sad about being banished, Melman is distressed that he has only 2 days to live and Marty is upset he's exactly like all the other zebras. Gloria comes along happily and gloats about the great time she's having. When she mentions Moto Moto and his interest in her, Melman gets jealous and they quarrel and stalk off in separate directions. Alex and "Marty" are left behind, until the real Marty comes along, and is offended that Alex could not tell the two zebras apart. Accusing Alex of only thinking of himself, he walks away.
As Melman sits inside a giraffe death hole, Julien and Maurice come to him. Julien advises Melman to tell Gloria how he feels. Gloria is at the hippo's watering hole, being charmed by Moto Moto. She asks why he likes her. Besides her plumpness, he can't answer anything else. Melman comes over and sees them together. He tells Moto Moto to take care of Gloria and rattles off a bunch of her favorite things, as Gloria watches surprised.
Inexplicably, the watering hole dries up, leaving only a tiny amount. Makunga comes along and suggests that the animals fight each other for the remaining water. Alex shows up and says that he will go and look for the reason for the water stoppage, which is off the reserve. If any animal goes off the reserve, it is fair game for hunters. Makunga, hearing the dissent among the other animals, says that he will confer with Zuba. Before leaving the reserve, Alex goes to the zebra herd and looks for Marty. Unable to find him, he shouts out that he's sorry. However, he recognizes Marty and asks him to accept his apology. Having made up, Marty accompanies Alex into the woods outside the reserve. Meanwhile, Makunga tells Zuba and Mom that Alex has gone out of the reserve. Zuba runs off immediately in search of his son, while Makunga laughs evilly.
At the watering hole, Julien and Maurice show up and declare that an animal sacrifice to the volcano will please the water gods. They need a volunteer. Melman, thinking that he has less than a day to live, volunteers. Cheering, the animals lift him up and take him to the volcano. Gloria protests, trying to talk Melman out of it, but he has made up his mind.
Alex and Marty go through the eerie woods and come up to the source of the water blockage - a dam erected by the NY tourists, led by Nana. They are suddenly attacked by spear-wielding tourists. Alex is caught in a rope trap. He tells Marty to go get help. Marty runs off.
At the volcano, Melman stands shakily at the edge of the precipice, overlooking the red-hot magma. Suddenly, Witchdoctor Joe shows up. He says that all giraffes have brown spots, so there's no such thing as Witchdoctor's Disease. Gloria runs up to Melman and tells him not to jump. However, as she runs up to the precipice, she stumbles and cracks it. Melman starts running towards her, past the crumbling precipice. She grabs him by his horns. They profess their love for each other. Just then, Marty runs in and tells them that Alex is in trouble and they need the plane.
At the crash site, the monkeys and penguins are quarreling over maternity leave (for the male monkeys). Gloria, Marty and Melman run up and tell them to get the plane ready immediately.
Alex is taken to the tourists' colony, where they plan to roast him for dinner. Just then, Zuba shows up and frees Alex. Seeing that the tourists are New Yorkers, Alex starts doing his famous dance. The tourists recognize Alex, who they thought was dead. At first bewildered, Zuba also joins in the fun. However, Nana still wants to eat them and aims the shotgun at them. Suddenly, the plane flies overhead and drops a capsule down, with a monkey-chain (several monkeys holding hands). The lions get on it and, thanks to some miscommunication up the monkey-chain, the penguins are ordered to take out the dam. As Nana tries to shoot the plane, standing on the dam, the capsule slams into the dam, destroying it and letting the water flow towards the watering hole.
Meanwhile, at the volcano, Julien and Maurice stand alone at the precipice, wondering about the sacrifice. Suddenly, along comes Mort, who survived the fall and the ocean, and is currently trying to survive the huge, scary shark that's followed him inland. As the shark lunges at the lemurs, they hang off the edge of the precipice, while "Jaws" plummets to a fiery death below. At that moment, they see water flowing towards the watering hole, leading them to believe that the sacrifice worked.
The parched animals are overjoyed to see the water back. They are happier when they see Alex and Zuba standing proudly on the capsule, floating on the water towards them. Makunga comes along and haughtily tells them that, though they brought the water back, Alex is still banished. Alex tells him that he has a gift for him and gives him Nana's handbag. Makunga takes it happily, but the gift has an accompaniment inside the capsule - Nana! Seeing her handbag around Makunga's shoulder, she screams "Bad kitty!" and attacks him, leading him away by the ear. Makunga picks up the fallen scepter and tells Alex that they're both Alpha Lions, as the animals rejoice.
We then see the animals at a wedding... of Skipper the Penguin and his beloved wooden Hulu dancer doll. The penguins and monkeys fly off in the plane, while Alex, Marty, Melman, Gloria and the lemurs stay back in Africa. Alex tells Zuba that they'll be staying with them. Zuba has an angry look on his face, but does the "happy face/angry face" gag, with his paw. They all laugh. Melman and Gloria look lovingly at each other. Marty ribs Alex, saying he's not Marty. Alex laughs, but just for confirmation, looks at Marty's behind, where a big scar (Alex's dental impression - from the previous movie) is. They walk towards the watering hole.
You can send in your spoiler to other movies by going here.