In the 1980s, Nike was locked in an epic war with Reebok for control of the sneaker market.

Nike had enjoyed huge success by using popular sports stars to promote its products, but Reebok — largely by targeting the female market when jogging exploded in America — managed to pass its rival with revenue of $1.4 billion in 1987.

In response, Nike engaged Portland advertising firm Wieden & Kennedy to create a new campaign that would broaden its appeal.

Dan Wieden knew the key was to somehow resonate with everyone from women who were exercising for the first time to the best athletes in the world.

But the night before he was scheduled to present to Nike boss Phil Knight and the rest of the company’s hierarchy, Wieden was still looking for a tagline to tie the campaign together.

His inspiration would come from the most unlikely of places, according to Dezeen Magazine.

Around 10 years earlier, a man named Gary Gilmore received mainstream media attention after murdering two men in separate incidents in Utah.

Gilmore, then 35, had endured a troubled upbringing and spent half his life in prison for a series of violent crimes including armed robbery.

He’d been released from an Indiana prison and moved to live with a distant cousin in Utah in an attempt to turn his life around.

But he quickly returned to his previous lifestyle and, in July 1976, robbed and murdered gas station employee Max Jensen, and then killed motel manager Bennie Bushnell the following evening.

Gilmore was quickly caught, convicted and sentenced to death. Instead of trying to fight for his life, he appeared to welcome the verdict and chose to be shot by a firing squad instead of being hung.

Capital punishment was suspended in the US from 1972 to 1976, so there was high interest in Gilmore’s case.

Gilmore’s mother and the American Civil Liberties Union both fought to have his execution stayed, but Gilmore himself resisted the efforts, telling them to “butt out.”

So, after a last meal of steak, potatoes, milk and coffee — of which he only consumed the milk and coffee — Gilmore was put in front of the firing squad on Jan. 17, 1977.

When asked if he had any last words, Gilmore famously said: “Let’s do it!”

It was a line that stuck with Wieden, and for some reason came to him as he sat trying to finalize the Nike campaign in 1988.

“The night before the presentation, I got worried the stuff didn’t hang together enough … so I sat down, I think it took me about 20 minutes, and I wrote four or five lines,” Wieden said.

“I was trying to write something that would tie it up so it could speak to women who had just started walking to get in shape to people who were world-class athletes — and it had the same kind of connection with them.

“And for some damn reason I thought of Gary Gilmore … Gary had killed some people in Utah, which is not a good place to kill people because they kill you right back. He was convicted and sentenced to die by firing squad. So they brought him out, put him in the chair … and before they put the sack over his head, they asked him if he had any last words and he said, ‘Let’s do it.’

“I remember when I read that I was like, ‘That’s amazing — how, in the face of that much uncertainty, do you push through that?’ I didn’t like the ‘let’s’ thing, I just changed that because otherwise I would have to give him credit, now I don’t really have to.”

The “Just Do It” tagline first appeared in a 1988 commercial featuring 80-year-old runner Walt Stack and was wildly successful.

It allowed Nike to regain the lead from Reebok in 1990 and grow its worldwide sales from $877 million to $9.2 billion in the decade after it was launched.