Peter Farrelly helped usher in a new era of raunchy and ridiculous comedies, the kind where idiots get their tongues stuck on icy poles and nervous teenagers endure painful prom-date catastrophes.

But now, the director and co-writer of “Dumb and Dumber” and “There’s Something About Mary” has turned his attention to a very different kind of movie: a historical drama that deals with weighty issues of race and class, stars an Academy Award winner and nominee, and is racking up film festival prizes.

“Green Book,” out Friday in Washington and select cities, stars Mahershala Ali as a concert pianist and Viggo Mortensen as the Bronx bouncer who drives him through the Deep South for a tour. The movie takes its name from“The Negro Motorist Green Book,”  the popular travel guide that helped African Americans travel during the Jim Crow era.

“It’s definitely a departure from what I’ve done, but it wasn’t like I thought at that point in my life, ‘You know I should do something different,’ ” co-writer and director Farrelly said. “By the way, I should have been thinking that way, but I didn’t. It’s just that the heavens gave it to me.”

The heavens embodied by Brian Currie, that is.

In 2015, Nick Vallelonga told his longtime friend Currie the story of how his father was the driver for a world-renowned New York musician. 

The record company had hired Tony Lip, the toughest bouncer at the Copacabana nightclub, to make sure Don Shirley, a black pianist, would safely make it to his concert gigs during a 1962 tour through the segregated South, where traveling was perilous for black Americans.

They decided to write a screenplay, and Currie soon told Farrelly, whom he had met while acting in his movies.

“He couldn’t get it off his head,” Currie recalled. “From then on, he just kept calling me, like, ‘Brian, forget about everything else. . . . Keep telling me about the Don Shirley and Tony Lip story.’”

Shirley was a musical prodigy with refined tastes who held several honorary degrees, and Lip was an Italian American who lived in the Bronx and had prejudiced attitudes. “[Currie] said, they went on the road together, and a lot happened, and they became friends,” Farrelly recalled. “I was like, really?! This guy, a black concert pianist and the racist bouncer became friends? . . . That’s the thing that grabbed me.”

Farrelly joined the writing team, and they pored over recorded interviews of Lip and Shirley (both men died in 2013). Later on, Ali was instrumental in offering changes to dialogue. “A genius is playing a genius,” Currie said. “He took it upon himself to say, okay, this is how I feel Dr. Shirley would be.”

Throughout the course of the characters’ road trip, the audience sees the indignities of traveling while black. Filming took place in several locations actually recommended in the “The Negro Motorist Green Book,” such as the motel where Motown acts would stay when performing in New Orleans.

Farrelly said he wasn’t any more nervous making a drama dealing with such fraught themes than he was when he made comedies. “It’s just a different story, but it didn’t feel like starting over. It felt like a continuation of what I did,” he said. “I entered this in the same state of anxiety, to make sure you’re doing everything you can to make the movie as good as it can be.”

It’s not uncommon for comedy writers and directors to shift to drama and get critical acclaim (Adam McKay’s “The Big Short” and Jordan Peele’s “Get Out” both won Oscars), but the trend is especially prevalent recently: Jonah Hill’s “Mid90s” and David Gordon Green’s “Halloween” both came out this fall.

The movie industry has seen the decline of the kinds of hit summer comedies that used to be so commonplace when Farrelly and his brother Bobby helped reshape the genre (the successes of the comedies “Crazy Rich Asians” this year and “Girls Trip” in 2017 are more the exception now than the rule). These days, studios are putting out fewer comedies and more superhero and sci-fi films.

And perhaps the sorts of features that characterized Farrelly Brothers comedies wouldn’t fly today, in an era of intense scrutiny and rapid social-media controversies. Wouldn’t the use of a fat suit in “Shallow Hal” face fierce blowback? What about Warren, the developmentally disabled character in “There’s Something About Mary”?

Farrelly wonders. Some critics at the time pilloried them for the Warren character, but Farrelly said they received only positive fan mail about him, including from people who wrote that the movie inspired them to spend more time with relatives who have disabilities.

Any criticism “didn’t bother us because we didn’t believe it,” Farelly said. “In my heart, I knew it wasn’t true, and just from the reaction we got from real people.”

With Warren, “were there laughs around him? Sure. But he wasn’t the laugh.”

The Farrelly brothers also produced the 2005 comedy “The Ringer,” featuring several actors with intellectual disabilities and starring Johnny Knoxville as a guy trying to rig the Special Olympics (which actively endorsed the movie).

“It’s just those kind of things, yeah, it would be harder to do it today,” he said. “The Special Olympics were on board when we did that movie; they were one of the producers. But they probably would have to think twice about it today, because of the criticism they’d get.”

Although “Green Book” is decidedly a drama, there’s humor laced throughout. That wasn’t an element Farrelly set out to incorporate; in fact, he and his co-writers went out of their way not to add gags, and instead focused on the odd-couple chemistry.

“There are no jokes in this. Anything that comes out of this is organic, character-driven — it’s a thing between these two guys,” Farrelly said. “On paper, this wasn’t as funny as the movie turned out to be.”

The nuanced performances of Mortensen and Ali “elevated it,” Farrelly said. “They took little smiles and turned them into laughs.”

Ali’s Shirley serves as the straight man to Mortsensen’s Lip, getting laughs from a simple eyebrow raise or smirk.

It certainly helped that Lip had naturally funny tendencies, especially in his relationship with food. Mortsensen eats on screen a lot; he gained 25 pounds before filming, and then another 20 during the seven-week shoot, a likely outcome after eating 15 hot dogs in a day and taking it upon himself to add real-life Tony Lip tics, such as folding an entire pizza in half and eating it like a sandwich.

It’s a good thing the movie ended up having as many laughs as it did, the filmmakers said, because they make the film more accessible. They give breaks from the heavier scenes that show the dangers of traveling for black people in an era of “sundown towns,” which banned African Americans after dark.

“In the middle of [filming], we had a very diverse crew, and a lot of crew members would come forward, and they were moved by what was happening and seeing it, or angered in some ways by the scenes,” Farrelly said. 

Farrelly “never set out to make a message movie,” he said, “but while we were making the movie, you start recognizing what you’re doing here.”