Police have praised two armed bystanders after they shot and killed a gunman who opened fire on diners at a restaurant in the US state of Oklahoma.

Oklahoma City police said four victims were injured on Thursday before the duo confronted the shooter as he fled the scene and "fatally shot him".

The gunman shot three people. A fourth person broke his arm. All the victims are in good condition, say police.

Police named the deceased suspect as 28-year-old Alexander Tilghman.

Police Capt Bo Mathews told reporters that the armed civilians, Juan Carlos Nazario, 35, and Bryan Wittle, 39, "took the right measures to be able to put an end to a terrible, terrible incident".

Mr Nazario and Mr Wittle did not know each other, but both retrieved firearms from their vehicles to confront the shooter.

Capt Mathews said the suspect, Mr Tilghman, shot at customers from outside the door of the restaurant, adding that "it could have been really tragic" if the gunman had actually entered the confined space.

"It doesn't look like [Tilghman] knew anybody at the restaurant. He didn't work at the restaurant," Capt Mathews said.

"It looked to me like a random event."

What do we know about the attacker?
Mr Tilghman had a YouTube channel where he posted videos talking about demonic attacks, Fox 25 News reported.

But he held an active licence as an armed guard, the Oklahoma Council on Law Enforcement Education and Training told KOCO 5 News.

In one of his clips, he complains of a demon-possessed squirrel, and in another of his refrigerator attacking him.

In a video uploaded weeks before the attack, he said: "I am under hardcore demonic attack, you know.

"I really need some real people in my life so get in touch with me ASAP."

On a different YouTube page, a user claiming to be Mr Tilghman's brother said he was mentally disturbed, reports Fox 25.

The National Rifle Association (NRA) has cited the incident as another "example of how the best way to stop a bad guy with a gun is a good guy with a gun".

How the attack unfolded
Louie's Grill & Bar in north-west Oklahoma City had more than 100 customers at the time of the shooting.

Capt Mathews said the gunman was wearing ear and eye protection typically used at shooting ranges.

"Looked like his mind was made up that he was going to discharge his firearm once he got there," Capt Mathews said.

Mr Tilghman shot at people from the front door of the restaurant, but he did not enter the premises.

Three victims were injured as a result of the shooting, and a fourth fell and broke his arm.

Ron Benton, one witness, told News 4 the shots sounded like "a rack of plates crashing" followed by "a pop, pop, pop sound".

"I spotted the [shooter] walking north up the sidewalk, and pointed him out to the guy who had the weapon," Mr Benton said.

"It's like, every day you hear the same story but it was just very odd to be in the middle of it."