Image copyright Matt Hahn

When a burglar opened a safe he had stolen from a house, what he found would send another man to prison. But in an extraordinary twist - it also saved the trespassing thief from serving a life sentence.

Matthew Hahn's drug use started in his early teenage years with marijuana, then led to meth.

He dropped out of high school and resorted to stealing to support his habit.

In 2001 he came out of prison after serving a five-year sentence.

He had been convicted of two serious offences under California's three strikes law so if he ever got arrested again, he would be facing a life sentence.

Hahn says he "did very well for a number of years... I had a great job, I was going to school, I was going to college. But then personal tragedy struck and my inability to cope led me to relapsing."

Image copyright Matt Hahn Image caption Hahn said as a young adult he resorted to stealing to support his habit

One of Hahn's closest childhood friends took his own life, which he said led him to months-long "binge of drug use and stealing".

Then one night in Los Gatos, California, in 2005 he brought home a stolen safe that would save his life.

The first thing he pulled out was a set of soiled diapers - "a surreal experience".

"There were a number of other things in the safe. There was a gun, there were photographs. There was personal paperwork for the person who owned it. And finally there was a digital camera card. And when I put that into my computer it revealed photographs of the person who owned the safe molesting an infant or a child."

He didn't at first realise what he was seeing. "Even the first photograph I looked at was odd, and I knew there was something weird about it, but I wasn't really sure what it was. And it wasn't until I saw subsequent photographs that I realised what I was seeing was an adult and a child."

Find out more

Matthew Hahn told his story to Emma Barnett on BBC Radio 5 Live

It wasn't an option to walk into his local police department and simply tell them he's been breaking into people's homes and happened to find evidence of a crime.

He knew he had to do something, but he also knew any felony conviction could result in a life sentence.

So Hahn put the camera card in a change purse, writing a note with the man's name and the address of the home he had stolen it from. He added: "Please remove this animal from the streets" and posted it to the police.

He asked his mother to watch for news reports about the story, after he lied and told her he found the item at a garage sale.

About a week later, she called and said a man had been arrested.

Hahn says John "Robbie" Robertson Aitken had reported the burglary to the police. When the local police department received the photographs, they called the man for questioning under the guise of meeting him to discuss the burglary. Hahn believes Aitken, then confessed.

Image copyright Matt Hahn Image caption Hahn was arrested numerous times

For Hahn, this wasn't the end. He continued to burgle houses and ended up in custody about eight weeks later after the serial number of a stolen item he sold on eBay was traced back to him.

He was then facing his third strike.

The officer that arrested him - and knew him from prior run-ins around town - asked: "What happened to you, you were doing so good?".

"Well, at least I gave you Aitken", he said, explaining how he had posted the photos.

While Hahn was in jail awaiting trial, he was approached by the district attorney who was prosecuting Aitken, and asked if he'd be willing to testify to having stolen the safe.

Because Hahn was charged with multiple felonies and had two strikes already, he was was facing "400-years-to-life".

He decided to testify about his crime, "I suppose at the expense of my ability to present my own defence."

Once he'd gone on the record as having stolen the safe, "I could really no longer present a viable defence for my own case".

You might also be interested in

Aitken was facing at least 25 years sentence for his crimes, and the sentencing discrepancy between him and Hahn led to petitions supporting Hahn and an offer of a plea deal from the district attorney.

Some people were saying he should be let out of jail on probation - a slap on the wrist for a career criminal - and others said he should be given a long sentence. In the end he was sent to prison for 14 years and four months, but served seven.

He and Aitken were in the same prison at one point - however Aitken was in protective custody and Hahn was in general population, so they never crossed paths. Because Hahn was a witness in Aitken's trial, they occasionally had court appearances on the same day.

"When the bus came to the jail to pick us up, he was in a cage in the front of the bus while I was just handcuffed and chained in the back. He never knew I was in there with him, but I recognised him."

They've never spoken, and Aitken is still in prison. Hahn says he has never questioned his decision to testify in the trial.

Image copyright Matt Hahn Image caption Matt and his wife Noelle are buying their first house together

While in prison, he thought to himself: "No matter what this prison experience was going to be, it was the last time I had to experience it". He started drug recovery, as well as studying books given to him by the mother of Aitken's victim, and meditating.

After prison he graduated from University of California at Berkeley. He found it difficult to find work as a felon, so became an electrician.

"I have a great job," he says now, telling the BBC that he and his wife have just purchased a home. "Amazing things are happening in my life today. I've definitely moved on from prison.

"But don't get me wrong. The first thing I thought of when I had the offer on the home accepted was, like, just 10 years ago I was still living in a cell and I'm going to have my own home".

Hahn says his biggest regret is the harm he caused to people he didn't know. He wishes he could take that back.

"I think the best I can do is pay the restitution for the crimes, which I did. And do my best going forward to tell my story [and] help other people who are struggling with addiction to not perhaps go down the same path."