The story continues from the events of the second film. Alex (Ben Stiller) has a nightmare about himself and his friends still stranded in Africa and finding they have all gotten old. He then wakes from his dream on his birthday, and the animals present him with a miniature model of New York City. Alex suggests to Marty (Chris Rock), Melman (David Schwimmer), and Gloria (Jada Pinkett Smith) that they should go to Monte Carlo to get the penguins to fly them back to New York City, which they agree to.
In Monte Carlo, the penguins and the two chimpanzees, Mason and Phil, disguised as the King of Versailles, keep winning in gambling until Alex's gang's attempt to reach them blunders and sparks chaos in the Hotel De Paris. The hotel security calls Monaco Animal Control officer Captain Chantel DuBois (Frances McDormand) to deal with the animals. But rather than capture them alive, DuBois desires their heads, mainly Alex's, as trophies. A high-speed chase ensues between the relentless DuBois and the animals in a truck driven by the penguins to reach their aircraft that was from the second film. The group departs on the plane, just barely escaping DuBois.
In the skies of France, the plane's engines fail and the plane crashes into a suburban rail yard as the authorities close in. They come across a circus train and bang on it, desperately trying to get in. Gia, a jaguar (Jessica Chastain), sees the four zoo animals and Alex is smitten with her upon first sight of her. Seeing their only chance of escape is on the circus train, the four larger animals desperately claim that they are circus animals themselves, which convinces Stefano the sea lion (Martin Short) and Gia to let them in despite the protests of Vitaly the tiger (Bryan Cranston). 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. Meanwhile, King Julien (Sacha Baron Cohen) falls in love with Sonya the bear (Frank Welker) and goes on a city tour across Rome. He accidentally breaks her tricycle, and buys her a motorcycle with the stolen coronation ring of the Pope. Meanwhile the others prepare for the performance at the Colosseum. Unfortunately, to the zoo animals' horror, the circus proves to be so terrible, the angered audience demands refunds, right to going to the point of chasing the circus to the departing train to London.
En route to London, the zoo gang is in despair of having wasted their money on the failing circus and not any closer to getting home. Stefano soon reveals to Alex that Vitaly was once their inspiration. Once a professional ring jumper who used to leap through incrementally smaller hoops to excite crowds and was always pushing himself to the limit, 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. An inspired Alex then has the train make a stop in the Alps and convinces the performers to rework their act to become the opposite of the world-famous human-only Cirque du Soleil as an animal-only lights and acrobatic show.
He encourages the animals to try pursuing their ambitions and advises others to change acts they are unsuited for. Similarly the zoo animals are trying out new things too. Heartened by Alex's vision, the zoo animals 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 & detained in Rome after causing problems with the local police officers while chasing the animals out of her jurisdiction, but escapes and researches Alex on the Internet, learning he was the missing lion from the zoo in New York. Once free, DuBois recruits her injured men, inspiring them with the French classic Non, je ne regrette rien, made famous by Édith Piaf, and heads toward the Alps, forcing the animals to proceed to London despite incomplete rehearsals. In London, the troupe prepares for the promoter in the audience, but Vitaly is discovered packing to leave. Despite the tiger's hostility to him, Alex convinces Vitaly to stay by reminding him of how he enjoys performing the impossible and suggests that he uses hair conditioner as a safer lubricant to perform his flaming ring jump. As a result, Vitaly's stunt is performed perfectly, which proves to be the opening of a spectacularly successful show. 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's plan to capture Alex, the lion is forced to confess that the four of them are just zoo animals trying to get home, disappointing the others who feel used by these lying amateurs who could have gotten them killed developing and performing their new acts.
Finally, both the ashamed zoo animals and the circus arrive in New York City. However, Gia, Vitaly and Stefano find that even after learning the truth about Alex's gang, they are ready to forgive their new friends without whom their lives and performances feel woefully incomplete. Likewise, the zoo group and Julien finally arrive at the gates of the closed Central Park Zoo, only to realize that their adventure has changed them too much to return to captivity and that they were "home" when they joined the circus. The zoo animals resolve to return to the circus and reconcile with their new friends, but they are then tranquilized and captured by DuBois. The zoo staff, delighted by Alex's reappearance, thank DuBois, incorrectly believing that she was trying to return the missing animals. Unnoticed, Julien manages to reach the circus (despite being darted by DuBois) and the penguins realize that the group had been ambushed. Upon learning about the zoo animals' plight, Gia and Vitaly convince the circus animals to rescue their friends and they set out for the zoo, performing aboard a flying circus, with the rescue mission dubbed "Operation: Afro Circus Rescue."
Meanwhile at the zoo, Alex awakens to find that he along with Marty, Melman, and Gloria are in their enclosures, surrounded by tall chain-link fences. DuBois steps on stage to receive a million-dollar check of appreciation from the zoo, but at the same time secretly loads a poison-filled dart into a gun which she hides inside a foam finger in preparation to kill Alex. The circus animals arrive in time to stop her and a massive brawl occurs where the circus uses all of what they had developed as part of their revamped act. As the group tries to leave, the insane DuBois attempts to kill Stefano, who is stranded at the zoo. However, Alex saves Stefano and all the animals then defeat DuBois and escape.
Heartened by this valiant demonstration of their new friends' love, Alex and his friends decide to join the circus permanently. With the circus reunited, the animals all happily proceed with their American tour. Meanwhile, thanks to Skipper, DuBois and her men find themselves, oddly enough just like Alex and his friends in the first film, inside shipping crates on a cargo ship bound for the island of Madagascar.