During the weeks before his suicide, ROBIN WILLIAMS was clearly “hurting” as he struggled to maintain his sobriety with a last-ditch stint in rehab, The ENQUIRER has learned.

Ronald Backes, a former Olympic athlete who now heads a Christian ministry, bumped into the troubled star at a Minnesota coffee shop, and provides rare insight into Robin’s last days.

“He looked like he was hurting,” Backes, a devout Christian, told The ENQUIRER in an exclusive interview.

“What happened to him is a real tragedy. I wish I could have had a more in-depth conversation with him about faith.”

Robin, who’d long battled addictions to alcohol and cocaine, was participating in a program for maintaining long-term sobriety at the Hazelden Addiction Treatment Center in Lindstrom, Minn., when he posed for a picture with Ronald on June 30.

As the photo shows, Robin was gaunt and unshaven. His cheeks were sunken and flushed red, and he wore long black shorts with a black T-shirt that bore an eerie image of the skeleton of famed Mexican revolutionary Pancho Villa.

The Oscar-winning actor and two pals were drinking coffee and snapping pictures of each other when Ronald offered to take a photo of all three together.

“I told him that I liked his work, and he said, ‘Thanks!’” recalled Ronald, 51.

“Then I asked if he’d take a picture with me, and he said, ‘Sure!’ He was a considerate man.”

The two men posed in front of the coffee shop’s trademark moose with their arms draped around each other’s shoulders. Hazelden tightened security when Robin showed up, and clients were told to stay away from the lodge side of the campus where the actor was undergoing treatment.

“We heard through the grapevine that he was there, but we were told we were not allowed to go over there,” said a Hazelden client who was in rehab the same time as Robin.

“Some guys tried to sneak over there, but they were caught and told not to do it again.”

In a different photo, shot at a taco restaurant in Mill Valley, Calif., on the evening of August 5 as he ate with wife Susan, Robin appeared depressed.

The actor is seen slumped against a wall illuminated by a shaft of light.

The casual Mexican eatery is about six miles east of the couples home. An onlooker said: “He seemed down and he had his hand clutching his chest.

“He didn’t attract that much attention from other people because he’s often in town. He was with his wife. She had her hand on her forehead and both of them looked pretty serious.

“It’s very hard to believe that just a few days later he was dead.”

But for Backes, a former shotput thrower, Robin came across as “a very nice man.”While Robin long struggled to beat his drug demons, he was still able to make wisecracks about his substance abuse.

“Cocaine is God’s way of telling you that you make too much money,” he once joked.

Robin was also amazingly candid about his drug use with writer Andy Dougan, author of “Robin Williams: A Biography.”

“The weird thing about the drug period is that I didn’t have to pay for it very often,” Robin told Andy.

“Most people give you cocaine when you’re famous. It gives them a certain control over you; you are at least socially indebted to them.

“The more f**ked up you get, the more they can work you around. You’re being led around by your nostril.”

On June 29, Robin dropped by the Dairy Queen in Lindstrom, ordered a vanilla cone and posed with a DQ employee, 15-year-old Abby Albers.

She told a local newspaper that the actor was the “only famous person” she’d ever served.

But the 63-year-old star looked glum and sported the same gray stubble seen in Ronald’s photo.

The DQ picture was posted to Facebook, prompting Robin’s publicist to admit that he was in rehab “taking the opportunity to fine-tune and focus on his continued commitment” to sobriety.

Sadly, it was a battle he never won.