Peter Farrelly helped usher in the 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 one Academy Award winner and another nominee and is racking up film festival prizes.

“Green Book,” which opened last week, stars Mahershala Ali as a black concert pianist and Viggo Mortensen as the white bouncer who drives him through the Deep South for a tour in the 1960s. 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,’ ” Farrelly said. “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 Hayes Currie, that is.

In 2015, Nick Vallelonga was talking with his longtime friend Currie, an actor who was in Farrelly’s “Me, Myself and Irene.” He told him the story of how his father, called Tony Lip by his friends, was the driver for a world-renowned New York musician named Don Shirley.

Shirley’s record company had hired Tony Lip, the toughest bouncer at the Copacabana nightclub, to make sure Shirley could safely make it through the segregated South, where traveling was perilous for black Americans.

Currie relayed the story to Farrelly.

“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 encouraged Vallelonga and Currie to write a movie script, then joined the writing team himself. They pored over recorded interviews of Lip and Shirley (both men died in 2013).

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

Same game plan

Farrelly approached the making of a film with such fraught themes the same way he did silly 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 unprecedented for comedy writers and directors to shift to drama (Adam McKay went from “Anchorman” to “The Big Short”). Plus, the movie industry has seen the decline of the goofy comedies that were so commonplace when Farrelly and his brother Bobby helped reshape the genre. 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 about that, too.

“It’s just those kind of things, yeah, it would be harder to do it today,” he said. He and his brother (who was not involved with “Green Book”) “probably would have to think twice about it today.”

Humor, not jokes

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 Mortensen’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. Mortensen eats on screen a lot; he gained 20 pounds 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, Farrelly 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.”