One prisoner in upstate New York just got a major stroke of luck.

A wrongly convicted man walked out of a Buffalo courtroom on Wednesday and breathed freedom for the first time in nearly three decades – thanks in large part to investigative journalism by Golf Digest magazine.

Valentino Dixon was greeted by bright sunshine, chirping birds, his mom, daughter and other loved ones at Erie County Court, after his conviction for a 1991 murder was vacated.

“I love y’all,” Dixon shouted after trading prison duds he’d worn at Attica for jeans and a T-shirt. “It feels great.”

While incarcerated for 39 years to life, Dixon got back to his childhood love of drawing.

Then one day, a warden handed him a picture of the 12th hole at Augusta National golf course, hooking Dixon on drawing lush greens, rolling hills, bunkers and trees of golf courses.

Dixon became a prolific artist and his work drawing golf courses caught the attention of Golf Digest magazine in 2012, setting in motion a remarkable series of events that ended in his release on Wednesday after 27 years behind bars.

“It took about a hundred drawings before Golf Digest noticed, but when we did, we also noticed his conviction seemed flimsy. So we investigated the case and raised the question of his innocence,” the magazine’s Max Adler penned of Dixon – who has never played the game.

“The case is complicated, but on the surface it involves shoddy police work, zero physical evidence linking Dixon, conflicting testimony of unreliable witnesses. . . All together, a fairly clear instance of local officials hastily railroading a young black man.”

Articles in Golf Digest and in other media grabbed the attention of Georgetown University students working on prison reform issues.

Their additional investigation and work of appeals lawyers finally led authorities to acknowledge that Dixon didn’t kill 17-year-old Torriano Jackson on a Buffalo street corner in 1991.

Lamarr Scott, who is doing 25 years in prison for an unrelated attempted murder, admitted to the killing in court.

“There was a fight. Shots were fired. I grabbed the gun from under the bench, switched it to automatic, all the bullets shot out. Unfortunately, Torriano ended up dying,” Scott told the court. “I dropped the gun and ran and it was over and done with.”

Scott said he had got the murder weapon, a Tec-9 semi-automatic, earlier in the day from Dixon.

Judge Susan Eagan let stand Dixon’s conviction for criminal possession of a weapon — which carried a sentence of five to 15 years and would have run out long ago.

“You are eligible for release today,” Eagan said, bringing applause and shouts from courtroom supporters.

Even in victory, Donald Thompson, one of Dixon’s lawyers, bemoaned that it took his client’s art catching the eye of Golf Digest to win freedom.

“Once a case crosses a certain threshold of media attention, it matters, even though it shouldn’t,” Thompson told Golf Digest. “It’s embarrassing for the legal system that for a long time the best presentation of the investigation was from a golf magazine.”

Outside court, Erie County DA John Flynn insisted Dixon is no martyr for justice.

“Mr. Dixon is not an innocent man. Don’t be misguided in that at all,” Flynn told reporters after the hearing, calling Dixon “an up-and-coming drug dealer in the city of Buffalo” at the time of the shooting.

“Mr. Dixon is innocent of the shooting and of the murder for what he was found guilty of … but Mr. Dixon brought the gun to the fight. It was Mr. Dixon’s gun.”

Dixon plans to keep drawing and volunteering to help other prisoners who might have also been wrongfully convicted.

“If you don’t have any money in this system, it’s hard to get justice because the system is not equipped or designed to give a poor person a fair trial,” he said. “So we have a lot of work ahead of us.”

Dixon’s daughter, Valentina Dixon, was a baby when her dad went to prison. She brought her 14-month-old twins, Ava and Levi, to court to meet their grandfather.

“We’re definitely going to go shopping and go explore life,” she said. “I can’t wait to get him a cellphone and teach him how to Snapchat.”

Dixon’s mom Barbara Dixon said she leaned on her faith all these years, praying Valentino would someday be vindicated.

When asked what the family had planned next, she said: “We’re going to Red Lobster and everybody’s invited.”

With Post wires