A heroic plainclothes cop was shot in the ankle during a wild, early-morning police shootout on a South Bronx street Saturday — but still managed to return fire, putting four bullets in the teenage suspected gunman.

Officer Sherrod Stuart, 25, and his accused shooter, Christopher Rice, 19, remained in Lincoln Hospital. Rice, who has a history of violence against cops, was in serious condition.

Stuart, a four-year cop who is the son of an NYPD detective, hosted Mayor de Blasio and Police Commissioner Bill Bratton as proud bedside visitors.

“What an impressive young man who went into this dangerous situation and handled himself so well,” de Blasio said.

A steady stream of cops also visited Stuart, a member of the 40th Precinct Anti-Crime Unit.

Rice was struck four times — on the right side of his neck, his abdomen, his thigh and his hand.

“He’s in a lot of pain. He’s pretty shaken up. They’ve got a lot of pain medicine in him now,” one cop said as he left the hospital.

“The bullet is still in him. It’s pretty bad. It hit two bones.”

Stuart had been responding with fellow officers to multiple 911 calls from the neighborhood around Lincoln and Third avenues in Mott Haven.

A fight had broken out at a “jump-up” party — an unlicensed, pop-up nightclub — at a loft just east of the Major Deegan Expressway.

As many as 200 people were at the party, and the fight had spilled outside into the street, where gangbangers were battling one another “with guns and bats and knives,” Bratton told reporters.

Rice turned a gun on arriving officers, shooting Stuart in the right ankle, Bratton said, adding that the cop fired back.

“He returned gunfire, striking the male suspect four times,” he said.

Rice was hit on the right side of his neck and in his abdomen, thigh and hand.

Two other cops joined Stuart in the gunfight. When the smoke cleared, three guns lay scattered at the scene, including the .380-caliber semiautomatic that cops say was used to shoot Stuart.

One resident said violence regularly breaks out in the gritty neighborhood.

“They like to shoot,” the neighbor said. “This is a weekend thing. They get high, they get stupid, they start arguing amongst each other, and they try to kill each other.”

Big, volatile jump-up parties are common, another neighbor said, adding, “I just keep walking.”

Although only a teen, Rice already had five prior arrests, starting with an assault on a civilian when he was just 16.

Twice he has resisted arrest, most recently in March at Willis Avenue and East 137th Street.

In that instance, Rice and others were told by cops to leave the corner, and he refused, sources told The Post.

Rice then fought the cops who tried to handcuff him — and at the station house he punched a cop after getting uncuffed, sources said.

Just three hours before Saturday morning’s police shootout, Rice had been let out of a Bronx courthouse after an overnight arraignment on fare-beating charges, Bratton said.

Five stabbing victims from the original fight that started Saturday morning’s chaos were also hospitalized, he said.

The mayor hailed the NYPD’s speedy response.

“The fact is that backup came quick. His fellow officers did all the right things to subdue these criminals,” de Blasio said. “This is obviously a large group of people in a fight. NYPD officers handled this situation, defused this situation, got the guns and, as you heard, won the day.”

Additional reporting by Larry Celona and Laura Italiano