An NYPD officer was shot in the ankle early Saturday while breaking up a melee in the South Bronx, and he critically wounded the gunman, the police commissioner said.

The shooting happened as the officer, Sherrod Stuart, responded to “a very large ‘jump-up’ party with anywhere from 100 to 200 people,” Police Commissioner William Bratton said at a pre-dawn news conference at Lincoln Medical Center in the Bronx, the hospital where Stuart was in stable condition later in the day.

Stuart, 25, whose four-year anniversary with the NYPD was Saturday, and his partner were on plainclothes patrol when they were dispatched about 2:10 a.m. to reports of a large fight with guns, bats and knives in front of 2505 Third Ave., near the scene of an unlicensed club hosting the party, Bratton said.

Stuart and his partner began chasing a suspect, Christopher Rice, 19, who fired at them, Bratton said. Stuart was hit in the right ankle and shot Rice four times, Bratton said.

Rice was also brought to Lincoln hospital, where he was in critical condition, police said.

advertisement | advertise on newsday

Five people were also hospitalized after being stabbed during the brawl. A police spokeswoman said yesterday afternoon that she did not know the extent of their injuries.

“What an impressive young man who went into this very dangerous situation and handled himself so well,” said Mayor Bill de Blasio, who visited Stuart at the hospital with Bratton.

“Thank God his injuries are not life-threatening,” de Blasio said.

Police found a .380-caliber semi-automatic gun at the scene of the shooting, on Lincoln Avenue, and three more firearms and a knife at the scene of the fight, near East 137th Street and Third Avenue.

Rice has five prior arrests, including one for fare-beating, Bratton said. He said Rice was freed from court lockup on the fare-beating charge at 11 p.m. Friday, three hours before the melee.

Get the Newsday Now newsletter!

The best of Newsday every day in your inbox.

Stuart’s father is an NYPD detective who is on active duty with the Army, Bratton said.

“A police family,” de Blasio said.