From left, Ben Hardy, Rami Malek, Lucy Boynton and Joseph Mazzello accept the award for best ensemble for “Bohemian Rhapsody” at AARP magazine's 18th annual Movies for Grownups Awards at the Beverly Wilshire hotel Monday in Beverly Hills, Calif. (Matt Sayles/Invision for AARP the Magazine/AP)

It’s been, by any measure, a difficult time at Twentieth Century Fox.

The studio of “Avatar” and “All About Eve,” of “The French Connection” and “The Sound of Music,” is preparing to downsize considerably as it is swallowed by Disney as early as the end of the month. By some estimates, several thousand jobs could vanish. On a visit to the lot last year, a reporter came upon an eerie scene, as executives worked on movies with a sense of weary finality.

Plenty of film history will be negated, too. And, of course, potential films. Disney is not expected to keep much of the main studio going; it already has a machine to take those big swings. (More specialized units like “The Shape of Water” unit Fox Searchlight and “Love, Simon” label Fox 2000 could come through unscathed.)

So the one thing the 83-year-old studio wouldn’t want is to go out on a sour note. Wednesday, it revealed it wouldn’t — thanks to a most improbable savior.

Parent company 21st Century Fox released its earnings report for the second quarter, almost certainly its last as a firm focused on scripted entertainment. Earnings were solid — when factoring out the sale of its Sky stake in Europe, they came in at 37 cents per share, four cents above analysts’ forecast. And filmed-entertainment profit? It was up 47 percent from the prior year’s quarter.

But it turns out the property that made the results respectable wasn’t a big superhero film. It wasn’t “The Simpsons” or any other long-running franchise that usually drives these kind of results. It was “Bohemian Rhapsody,” the one-off musical biopic about Queen frontman Freddie Mercury.

The profit increase “reflects higher contributions from the film studio led by the worldwide theatrical performance of ‘Bohemian Rhapsody’ (winner of two Golden Globes and nominated for five Academy Awards),” the studio noted in a release about the Rami Malek-starring picture and a surprise best-drama winner at the Globes last month.

The movie is, to say the least, an unlikely redeemer.

“Bohemian Rhapsody” struggled epically in development, going through a long and futile attempt with Sacha Baron Cohen, who clashed with guitarist Brian May and the other keepers of the Queen light. It saw numerous scripts that didn’t pass muster. Then when it did get made, director Bryan Singer was fired midway through because of alleged absences from the set.

The director, who has been accused by multiple people of sexual abuse, was disappeared from the film’s publicity campaign and has not been mentioned by others since it rolled out in the fall. The allegations have also caused awards groups to disqualify the movie.

Oh, and critics pretty manifestly disliked it.

Somehow, despite all that, “Bohemian Rhapsody” has become a massive hit.

With $209 million in domestic box office, it stands at the highest-grossing non-franchise movie in the United States for 2018, well ahead of even powerhouses such as “Crazy Rich Asians” and “Ready Player One.” With $833 million worldwide, it’s the seventh-highest-grossing movie worldwide of the year, ahead of installments in behemoth franchises such as “Fantastic Beasts” and Fox’s own “Deadpool.”

Maybe most prominent is how big it’s been for Fox. At the moment it stands as the sixth-highest-grossing movie globally in the studio’s history — and the highest not to come from a franchise or James Cameron. That it’s a legitimate contender to win Oscar best picture later this month — and a likelihood for Malek on best actor — only fudges the sundae.

The irony is that Fox’s last triumph is exactly the kind of movie Disney won’t make — but maybe should. That studio builds (and builds off) existing franchise universes, not the struggles of British rock stars. Yet “Rhapsody” has had the kind of global contagion effect Disney executives spend months dreaming about plotting. The movie is the highest-grossing musical biopic of all time worldwide, and outperformed monsters like “Guardians of the Galaxy” and “Up.” The film has captivated Mercury’s native England; it has prompted random bursts of cosplay in Japan.

So “Bohemian Rhapsody” is doing what Fox movies historically did — tell original stories it thought America wanted to hear — combined with the kind of global contagion modern Disney wants. The numbers represent the results that prompted Disney board members to buy Fox in the first place, yet won’t be the kind of movies they make once they have the studio. These are paradoxical times in entertainment.

Still, there’s something fitting about “Bohemian Rhapsody” as Fox’s final major film before the show doesn’t go on. The studio began in the 1930s under a dark cloud. Created when Joseph Schenck and Darryl F. Zanuck of 20th Century Pictures combined with the embattled Fox Film, it promptly underwent a series of crises. Anchor talent Will Rogers died in a plane crash. Spencer Tracy parted with the studio acrimoniously as he struggled with alcoholism. One of the remaining lead stars, Janet Gaynor, found herself caught in a box-office lull.

Yet within a decade, the new Twentieth Century Fox was producing a dizzyingly diverse group of hit movies, from upscale dramas such as “Gentleman’s Agreement” to Rodgers & Hammerstein adaptations to the films of Shirley Temple.

That “Bohemian Rhapsody” would begin so ignobly and then conclude with a flourish is in keeping with the studio’s finish-strong tradition — and makes it, perhaps, a fitting end to Fox.