LOS ANGELES — For 14 years, Tyler Perry has been Lionsgate’s secret weapon. As the rest of Hollywood underestimated the appeal of his movies time and again (and again), Perry served up 20 films to Lionsgate, selling more than $1 billion in tickets and pouring profits into the studio’s home entertainment coffers.

That partnership came to an informal close over the weekend with the release of Perry’s low-budget “A Madea Family Funeral.” As ever, box-office analysts misjudged interest. “A Madea Family Funeral,” ostensibly marking the final big-screen appearance by Perry’s gun-toting grandmother, sold an estimated $27 million in tickets at 2,442 North American theaters, or roughly 30 percent more than analysts had predicted.

The turnout was enough to challenge “How to Train Your Dragon: The Hidden World,” the megamovie in the marketplace, for first place at the weekend box office. In the end, “Hidden World” (Universal) pulled ahead to collect roughly $30 million at 4,286 cinemas, for a two-week domestic total of $97.7 million, according to Comscore. The big-budget animated sequel has collected an additional $277 million overseas.

[Read Tyler Perry’s essay about the end of Madea]

Universal also had a good three days with “Green Book,” the contentious winner of best picture at the recent Academy Awards. “Green Book,” the feel-good story of a white chauffeur and his black client in segregation-era America, took in about $5 million, more than double what it collected the previous weekend. “Green Book,” which got off to a poor start at the box office in November, has now collected $188 million worldwide for Universal and Participant Media.