Many days after bidding the penguins goodbye, Alex the African lion has a nightmare about himself and his friends still stranded in Africa and finding they have all gotten old. He then wakes up from his nightmare on his birthday, and the animals present him with a miniature model of New York City out of mud. Alex suggests to Marty the zebra, Melman the giraffe, Gloria the hippopotamus, and the lemurs, King Julien, Maurice, and Mort, that they should go to Monte Carlo to get the penguins and the chimpanzees, Mason and Phil, and fly back to New York City, which they agree to do.
In Monte Carlo, the penguins and chimpanzees have been saving up their daily winnings from the casino to fly back to Madagascar and bring their friends home. Alex and his gang see them and believe that they had ditched them to stay there, and their cover is blown. Animal control, captained by the overzealous Chantel Dubois, is called in to deal with the animals. A high-speed chase around the streets of Monaco ensues between the relentless Dubois and the animals in a truck driven by the penguins. They barely escape Dubois, who vows to capture them and add Alex's head to her collection of stuffed and mounted animals.
In the skies of France, the plane's gear assembly fails and it crashes into a suburban rail yard as the authorities close in. They come across a circus train and manage to gain entry, claiming that they are circus animals themselves. Stefano the sea lion and Gia the jaguar let them in despite the protests of Vitaly the tiger. The animals soon learn from Stefano that they are performing in Rome and London, where they plan to impress a promoter to get them on their first American tour. Before the zoo animals' claim is discredited, the penguins suddenly appear with a deal to purchase the circus themselves, resulting in the pleased departure of all the humans. Julien also starts falling in love with a tricycle-riding bear named Sonya. Meanwhile, the circus animals perform their act at the Colosseum in Rome, but the show proves to be a disaster, much to the zoo animals' horror. The angered audience demands refunds, right to going to the point of chasing the circus to the departing train.
En route to London, Stefano soon reveals to Alex that Vitaly was once a professional ring jumper who used to leap through incrementally smaller hoops to excite crowds and was always pushing himself to the limit. But his attempt at an impossible jump through a flaming pinkie ring ended in disaster when he burned his fur, (which he had coated in extra virgin olive oil in order to slip through the narrow opening), destroying his confidence in his talent and the whole circus suffered by his example. The train makes a stop in the Alps, where an inspired Alex convinces the performers to rework their act to become the world's first animal-only circus. Heartened by Alex's vision, the zoo and the circus animals develop sophisticated acts together and become closer friends in the process, especially Alex and Gia, who find themselves falling in love.
Meanwhile, Dubois is arrested in Rome after causing problems with the local police officers while chasing the animals, but escapes and discovers that Alex was the missing lion from the zoo in New York. Once free, Dubois recruits her injured men and they head toward the Alps, forcing the animals to proceed to London despite incomplete rehearsals. Alex finds Vitaly preparing to leave and convinces him to stay by reminding him of how he enjoys performing the impossible. He suggests that he uses hair conditioner as a safer lubricant to perform his flaming ring jump as well as fix his damaged fur. As a result, Vitaly's stunt is performed perfectly, and the show is a spectacular success. After the impressed promoter arranges for an American tour, Dubois shows up with a paper showing that Alex was missing. Though the penguins are able to foil Dubois' plan, Alex is forced to confess that the four of them are just zoo animals trying to get home, disappointing the others who feel used and lied to by the four of them. The zoo animals and circus go their separate ways but arrive in New York City at the same time. Realizing how much their adventures have changed them, the zoo animals find that their true home was with the circus. Before they can go back, however, Dubois tranquilizes and captures them. She is discovered by the zoo staff, who believe she is responsible for returning the missing animals. Julien and the penguins manages to get to the circus and convince the circus animals to rescue their friends.
Meanwhile, at the zoo, Alex awakens to find that he along with Marty, Melman and Gloria are in their old enclosures, which are now surrounded by tall chain-link fences. Dubois steps on stage to receive a million-dollar check of appreciation from the zoo, which she rejects, and secretly loads a poison-filled dart into a gun which she hides inside a foam finger in preparation to publicly execute Alex. The circus animals arrive in time to stop her and a massive brawl occurs where the animals use all of what they had developed as part of their revamped act. As the group tries to leave, Stefano is stranded, and Dubois attempts to kill him. Alex manages to save him him with a performance of the "Trapeze Americano", a trick he made up while pretending to be part of the circus, and all the animals then defeat the Dubois, and escape. Heartened by this valiant demonstration of their new friends' love, Alex and his friends decide to join the circus permanently and they start their tour across the country. Meanwhile, Dubois and her men find themselves inside shipping crates on a cargo ship bound for Madagascar, thanks to Skipper (just like in the first film).