Danny Boyle’s Slumdog Million aire is an exhilarating, un predictable coming-of-age story that moves with the speed of a freight train and springs as many visual surprises as an Advent calendar.

Adapting Vikas Swarup’s novel Q & A, Boyle and screenwriter Simon Beaufoy begin with the triumph of a young man from the Mumbai slums, Jamal (Dev Patel), on the Indian version of Who Wants to Be a Millionaire? In winning 10 million rupees, Jamal represents the dream of being lifted from poverty. But the TV show’s host (Anil Kapoor) finds the boy’s knowledge implausible, and he has Jamal arrested by a police inspector (Irfan Khan) who tortures him to make him reveal how he’s managed to cheat so successfully.

Jamal’s ordeal at the precinct serves as the frame for telling the hair-raising story of his childhood. An ingenious device moves the action in and out of a series of flashbacks: each question tossed at Jamal triggers a memory so piercing that its details are etched on his brain. How does he know about the Hindu god Rama? As little boys, he and his brother Salim were forced into hiding after seeing their mother murdered in a violent attack on Mumbai’s Muslims. “If it wasn’t for Rama, I’d still have a mother,” Jamal explains to the inspector.

How does he know the words to a popular Indian song? It’s the tune that young Jamal prepared as an audition for Maman (Ankur Vikal), who sheltered the boys along with many other children and sent them out to beg. The ones who sing most sweetly are promised a life of relative ease. They don’t know that the best singers are blinded before they’re sent out on the streets—that affliction triples their earning power. Maman is a combination of Fagin from Dickens’s Oliver Twist, the beggar king Peachum from Brecht and Weill’s The Threepenny Opera, and the monstrous hag who adopts a blind orphan and makes her sing for alms in D. W. Griffith’s silent-movie classic Orphans of the Storm.

Jamal’s relationship with Salim is complex. Salim is always alert to ways to make a quick buck—though, when the boys escape from begging in Mumbai and wind up at the Taj Mahal, it’s Jamal who lucks into a money-making scheme as an unofficial tour guide. And Salim lacks his younger brother’s moral compass. He gets the two of them away from Maman but leaves their friend Latika (Freida Pinto) behind. Latika is the love of Jamal’s young life, and he can’t forgive his brother for deserting her; he insists that they return to Mumbai to find her when they’re older. There she’s still Maman’s captive, operating in the red-light district as an exotic dancer. Salim saves her, but not for a better life: they both wind up in the entourage of a gangster named Javed (Mahesh Manjrekar) who’s even scarier than Maman. It’s years before Jamal sees either of them again.

The story has its gruesome side, but the filmmakers layer the melodrama with humor. In the first episode, starstruck Jamal, desperate for an autograph from his favorite Bollywood star, dives into a privy so that his smell will repel the crowds standing between him and the object of his adoration.

Visually, the movie is a feat of sorcery, constantly shifting, unified by Anthony Dod Mantle’s gorgeous cinematography, which takes its light-toned palette from the look of strobe-light filters and neon. (Loveleen Tandan is credited as Boyle’s codirector in India.) The only scenes that lack inspiration are the ones involving the lives that Salim and Latika lead in Javed’s orbit after the boys’ return to Mumbai.

Jamal convinces the cops that he won the 10 million rupees legitimately and gets to return to the program to try to double his winnings. But the concept of winning is complicated in Slumdog Millionaire; it has a bitter side. The children who diligently practice their songs for Maman believe they’re competing for a spot on easy street; when Jamal locates Latika for the third time, she’s living the high life in Javed’s mansion, but she’s in misery. In the final moments Boyle takes the film full circle: we end up in a Bollywood musical number. But as in the 19th-century novels that Swar up took as his model, we’re made to feel the cost of a happy ending.