It all started with a prayer of a direct message to actor Josh Brolin on Instagram.

What happened next improbably snowballed, turning two virtually homeless, nobody writer-directors into somebodies and helping an actor with Down syndrome realize his dream of becoming a movie star.

The result is Friday’s “The Peanut Butter Falcon,” an indie drama whose twisty backstory is one of those classic only-in-Hollywood tales.

But back to the beginning.

Tyler Nilson and Mike Schwartz were friends with showbiz jobs. Schwartz was an editor, and Nilson worked as a hand model in commercials, doubling for famous names such as Brad Pitt, David Beckham and John Slattery.

While volunteering at Zeno Mountain Farm, a California camp for actors, some with disabilities, they met Zack Gottsagen.

Gottsagen, now 34, grew up in Florida and has Down syndrome. He had been acting since he was a child.

Nilson, 38, and Schwartz, 40, were impressed with his talent, and after Gottsagen expressed his desire to become a movie star in 2014, the two vowed to write a script for him.

Unfortunately, the pair had little beyond an idea.

“We didn’t have managers, or agents, or famous friends and had nothing going for us,” Nilson tells The Post.

They also had very little money. Nilson says his hand-modeling work dried up, and he was forced to move into a tent in the California woods with Schwartz occasionally joining him.

“I was eating one piece of chicken, one half of a sweet potato and a spoonful of butter each day, trying to spend $5 to $10,” Nilson says.

The duo pounded out a script with a singular focus on somehow getting it made. It concerned Zak, a young man with Down syndrome (Gottsagen) who escapes an institution and goes on the run in North Carolina. He’s soon befriended by Tyler, a down-on-his-luck fisherman (Shia LaBeouf), and they hit the road on a journey to meet Zak’s favorite professional wrestler (Thomas Haden Church).

Getting the film made took some five years of hard work.

“Zack is somebody that I had made a promise to, along with Mike,” Nilson says. “When you’re a team like that, there’s something really nice about it. There’s a saying, ‘if you want to go fast, go alone, but if you want to go far, go together.’ ”

The writers initially had trouble getting anyone to read the script. Then, on Dec. 31, 2015, Brolin posted an Instagram message that said he wanted to “give back in 2016.” Nilson and Schwartz took that as an opening and DM’ed him their script.

“We messaged him that we could really use the help. We’re a couple dudes living in a tent,” Nilson says. “He got back to us in 10 minutes and he said, ‘I’d be happy to help you.’ That was our first big toehold.”

Brolin had originally planned to appear in the film, but had to drop out to make “Deadpool 2.” His involvement, however, opened doors in Hollywood.

The unknown writer-directors were soon able to assemble an enviable cast that included Dakota Johnson, Bruce Dern and John Hawkes in supporting roles.

The feature, the first for the writer-directors, as well as Gottsagen, was shot in Savannah, Ga., in 2017.

‘I feel like a more realized, well-rounded human.’

The actors generally stuck to the script but were given room to improvise, such as in one scene when LaBeouf’s character is laying down his rules of the road. As can be seen in the “Peanut Butter Falcon” trailer, Tyler asks Zak what rule No. 1 is, and Zak replies, “Party!”

The line was Gottsagen’s.

The movie won an audience award at this year’s SXSW Film Festival, and its existence has already changed the lives of those involved.

Gottsagen, who had been living in Florida and working at a movie theater, has his sights set on a move to LA. He recently signed with Jordan Peele’s manager.

The writer-directors are also better off.

“I feel like a more realized, well-rounded human,” Nilson says. “I got to be of service to something larger than myself and to my friend Zack.”

And also, “I can eat more than 300 calories a day.”