A Texas man facing 99 years in prison for a crime he didn’t commit credits a selfie for saving him.

When cops showed up at Christopher Precopia’s work at a lumberyard in Georgetown in September 2017 to arrest him for burglary with the intent to commit other crimes, he was stunned, KVUE reported.

“I had no idea why everything was happening, and I was lost,” Precopia said this week. Cops hauled him off to Williamstown County Jail and released him only after his family posted a $150,000 bond.

Precopia had no clue why he was being arrested or what he was accused of, but he later found out his ex-girlfriend from high school had gone to the cops with a fabricated tale.

The accuser said Precopia broke into her home in Temple and sliced an X into her chest with a box cutter. Her identity is not being made public because she is not being charged with a crime. She would later admit to Temple police that she reported Precopia because she had a rocky relationship with him several years earlier.

On the night of the alleged attack, Precopia was actually 65 miles away at a hotel in Austin with his mom, Erin Precopia.

Luckily, he decided to take a selfie of himself with his family that evening, which he posted on social media.

“By the grace of God, [the accuser] said it happened on the day when I can say totally, 100 percent, where he was at,” Erin Precopia said.

Precopia had a solid alibi, but authorities charged him anyway, something police experts told KVUE might have been presumptuous. Generally, police interview suspects before charging them with a crime, the station explained.

“You may not get any more information than you had, but it gives you an opportunity for the suspect to react, respond, deny,” according to Bruce Mills, a former Austin assistant police chief.

Police finally dropped the charges against Precopia nine months after his arrest when his lawyer, Rick Flores, took the alibi evidence to Bell County prosecutors.

“Most of the time, we deal with gray matters,” Flores said. “It’s not normally black or white. But this is one of those cases where I could definitely prove he did not commit this offense.”