A Texas man was shot in the leg by a witness who spotted him beating and stabbing his 16-month-old son in an apartment building courtyard, police said.

The man was shot Sunday afternoon at the Oak Forrest Apartments in Lewisville by a neighbor who grabbed a firearm and took aim to prevent further injuries to the child, who later died, police said.

The man, who is believed to be the father of the toddler, was arrested by responding officers. The good Samaritan who fired the shot that stopped the attack will not face criminal charges, Capt. Jesse Hunter said in a news release obtained by The Post.

The identities of both the father and the child have not yet been released, Hunter said Monday. There were no police records of prior incidents at the apartment or previous reports involving Child Protective Services, Hunter said.

Edward Carranza, who lives at the apartment complex with his wife, Ludi, told The Post he was taking a nap when he heard several people screaming. He initially ignored the commotion until he heard three or four gunshots and went outside, he said. Carranza saw the man holding the child and standing in a “big pool of blood.”

“He had an evil look,” Carranza told The Post. “The look that he had in his eyes was not a normal look.”

Carranza said the man was screaming repeatedly in the courtyard to get people to come outside. He then tossed the child onto the concrete before stabbing him multiple times with knives and a pair of scissors. That prompted one resident in the building to throw a recycling bin at the man in a failed effort to get him to stop. Another neighbor then went inside his apartment to grab a gun and opened fire on the man, Carranza said.

“He was trying to get people to come toward him,” Carranza told The Post. “He was screaming, ‘Come on, come out here’ again and again to try to get people to come see what he was doing.”

Another witness told police that the father was yelling “Jesus is coming,” according to the Dallas Morning News. Hunter, who confirmed that detail to The Post, told the newspaper that the incident was “probably the worst” he’s seen in his 20-year law enforcement career.

The attack occurred while the toddler’s mother was at work. She has been interviewed by detectives, according to the newspaper.

The boy’s father was expected to be booked into a jail in Lewisville late Sunday, but the charges he faces aren’t immediately clear as investigators await toxicology results.

Another resident at the apartment complex said she heard gunshots while walking her dog late Sunday.

“Some of my neighbors told me to get down,” resident Mary Phillips, 77, told the Morning News. “My lease is up in March. If I live that long, I’ll move.”

Another woman at the complex said she regularly saw the toddler’s father spending time on his balcony and had no reason to believe he was capable of such an attack.

“He was pretty normal,” Ciera Mills, 26, told the newspaper. “For this to happen is unbelievable.”