As police struggled to arrest a man who allegedly pulled a gun on McDonald’s workers for messing up his order, one of the officers turned toward the man’s car.

He saw a gun pointed at his fellow officers.

The officer swiped the gun to the side as it fired, the bullet grazing his arm and shooting up into the awning above the McDonald’s drive-through.

It was then that he got a look at the shooter – a 4-year-old boy.

Police said the boy fired because his father, Sadaat Johnson, had told him to shoot the officers. Aside from the intervening officer, no one was hurt. Johnson, 27, was arrested during the Monday afternoon incident and charged with felony child abuse and the threatening use of a dangerous weapon.

Salt Lake County Sheriff Rosie Rivera told KTVX she’s never seen anything like a 4-year-old shooting at law enforcement and that it is evidence that “the campaign against police” has gotten out of hand.

“Every officer that’s here today just can’t believe it,” Rivera told the station. “We’re beyond belief.”

Johnson is locked up in the Salt Lake County jail, according to sheriff’s records. It’s unclear if he has an attorney.

Around 1:30 p.m., Johnson went through a McDonald’s drive-through in Midvale, Utah, with two children: the 4-year-old and the boy’s 3-year-old sibling, the Unified Police Department of Greater Salt Lake told The Washington Post in a statement.

After McDonald’s workers gave him the wrong order, Johnson allegedly flashed a gun. Employees asked him to drive to the front of the restaurant while they fixed his order, the statement said. Instead, they called the police.

After arriving at the McDonald’s, officers ordered Johnson to get out of his car, according to the statement. When he didn’t obey, police said, they opened one of the car doors and dragged him out.

As they did, one of the officers turned toward the car and saw a gun pointing out of the back window, police said. That officer alerted the others that he’d seen a firearm while knocking it to the side as it went off. The bullet grazed that officer, causing a minor injury, and then shot upward, lodging in the awning above the drive-through window.

Officers arresting Johnson at first didn’t know the shooter was a child and could have easily returned fire, Rivera told KUTV. But the officer who sent the bullet off target yelled out “Kid!” to the others as soon as he saw the young face in the back seat, Unified police said in the statement. Officers did not fire any shots in return.

Rivera praised the officer who sent the bullet away from his peers and then let everyone know the gunman wasn’t a man at all.

“He’s a hero in my mind,” Rivera told KUTV. “He saved a life today.”

Rivera told the station that her investigators believe Johnson told his son to shoot the officers.

“This is a sad day for law enforcement and our community,” the sheriff said in a statement. “To have an adult think it is OK to encourage a 4-year-old to pull a firearm and shoot at police illustrates how out of hand the campaign against police has gotten. This needs to stop.”

After the shooting, state social workers took custody of both children, Unified police told The Post.