An NYPD sergeant was fatally shot in the head and another officer badly wounded in a Wild West-style shootout with an ex-con in The Bronx on Friday, law-enforcement sources said.

Sgt. Paul Tuozzolo a 41-year-old married father of two, died without firing a bullet after he and several other officers chased down Manuel Rosales at about 2:45 p.m.

Rosales, who had a history of 17 arrests and served about two years behind bars in Suffolk County for possession of stolen property, was killed when other cops returned fire.

One of the officers who fired back is a recruit still in the Police Academy who had been on field training for just three days, police-union officials said.

The officers were responding to a report of an armed home invasion by Rosales at the residence of his ­estranged wife.

Sources said the shooting took place after cops were given a description of Rosales’ red Jeep and spotted it near 1460 Beach Ave. in a residential neighborhood in the Van Nest section.

They drove after Rosales for several blocks to 1575 Noble Ave., next to the Noble Playground, where they boxed in his Jeep.

Rosales, 35, of Brentwood, LI, opened fire from inside his Jeep with a .45-caliber semiautomatic as soon as Tuozzolo left his vehicle, shooting the 18-year NYPD veteran twice — once in the head and again in the chest.

Tuozzolo’s partner and an officer in another car fired back and fatally shot Rosales in a gunfight captured on video, sources said. A second gun was recovered from Rosales.

An unidentified officer assumed a combat stance and started shooting, the video showed.

“It’s pretty heroic, he’s under fire and returning fire. Who knows how many lives he saved by killing this guy?” a law-enforcement source told The Post.

Patrick Lynch, head of the Patrolmen’s Benevolent Association, added that the recruit who fired “responded like a professional of 30 years — he had three days.”

“He did right,” Lynch said. “Who did wrong was that mutt in his car.”

Rosales’ body could be seen hanging out the front driver-side window of the Jeep, with a puddle of blood below.

“Don’t feel sorry — he deserved it,’’ Rosales’ own dad told reporters.

Police recovered a blood-smeared Colt .45 semiautomatic at the scene.

A cop who worked with Tuozzolo called him “a stand-up guy, someone you would want on your side and as a partner.”

“The NYPD lost a good one ­today,” he added of the slain sergeant, who lived on Long Island with wife, Lisa, and sons Austin, 4, and Joseph, 3.

Ed Mullins, head of the Sergeants Benevolent Association, held back tears as he talked about Tuozzolo.

“Paul was killed doing what police officers do every day of the week,” Mullins said. “I’m proud to call him a friend.”

The other wounded cop, Sgt. Emmanuel Kwo, 30, a nine-year NYPD vet, was shot multiple times in the right leg and was in stable condition.

Tuozzolo was declared dead at the scene but taken to Jacobi Medical Center with Kwo.

Witnesses described a chaotic scene.

“I heard the screeching of the cars and I heard the shots, I heard the police screaming out codes,’’ said a woman who lives nearby. “My man told me it means officer down, stay in the house. I heard a lot of shots. It wasn’t one or two or even 10.

“How can you just get out of the car and start shooting? I saw all the officers running. It was insane. It’s good they got the person. It is unfortunate that the ­officer didn’t survive.”

Angel Chavez, 28, lives on ­Noble Avenue and said the other officers were distraught.

“One officer was crying. I knew that something bad had happened,” he said.

Neighbor Louis Pimental, 49, said “I heard like 20 shots. Then silence. Then cops came out of nowhere. It was chaos.”

Sources said Rosales’ 29-year-old estranged wife, the mother of their child, had been held hostage by him for nearly four hours before he fled the Bronx home.

A 3-year-old boy and another child, 13, were in the home along with a 50-year-old woman who made a 911 call.

The unidentified woman described Rosales’ Jeep, enabling cops to find him.

Contacted at her home, the woman who called 911 said: “I can’t talk.”

Sources also said Rosales went to his estranged wife’s home Thursday night and threatened to kill her. She had an order of protection against Rosales since 2015.

He was busted in July when he dragged her by her hair, and had a court date scheduled for Nov. 16.

Tuozzolo’s family arrived at the hospital in an NYPD helicopter shortly before 5 p.m.

A police source said Tuozzolo’s wife “was a mess, as expected.”

Mayor de Blasio and NYPD Commissioner James O’Neill also rushed to Jacobi.

“It is with tremendous sorrow that I inform you of the murder of Sergeant Tuozzolo.” de Blasio said at a somber news conference. “The city is in mourning and the NYPD is in mourning.”

Said O’Neill, “I always talk about what a great job this is, but there’s nothing worse than a day like today.”

The surviving cop, O’Neill said, was “devastated — as we all are.”

Gov. Cuomo issued a statement praising the cops who were shot, both from the 43rd Precinct, as heroes.

“Every day, the brave men and women of law enforcement selflessly serve our communities to keep the rest of us safe,” Cuomo said. “Today, a sergeant in the New York City Police Department has made the ultimate sacrifice in the line of duty, and another officer is undergoing treatment.”

Rosales had minor offenses in North Carolina and South Carolina, for littering and traffic violations. O’Neill said one of Rosales’ 17 arrests was for assault. Details on the others were not available.

Friday’s tragedy marks the eighth time this year that a New York City police officer has been shot in the line of duty — but the first fatal cop shooting in more than one year.

The last incident unfolded last month in Queens, where an NYPD detective was shot in the head with a pellet gun by a young Long Island woman.

On Feb. 4, while on patrol at the Melrose Houses in The Bronx, officers Diara Cruz, 24, and her 29-year-old partner Patrick Espeut were both shot by a suspect, who later turned the gun on himself.

On Feb. 20, veteran Officer William Reddin was shot and wounded in the hip during a traffic stop. His partner, Officer Andrew Yurkiw, also was struck, but his bulletproof vest managed to stop the round.

In October 2015, a career criminal fatally shot NYPD Detective Randolph Holder in East Harlem following a foot chase.

In December 2014, NYPD Officers Rafael Ramos and Wenjian Liu were ambushed and fatally shot by a crazed ex-con as they sat in their marked patrol car in Brooklyn.

Additional reporting by Chris Perez, Khristina Narizhnaya, Abigail Gepner, Sarah Trefethen, Keldy Ortiz and Bob Fredericks