A city correction officer was stabbed while trying to break up a brawl between a bouncer and a pair of unruly customers at a Brooklyn bar, law enforcement sources and officials said Wednesday.

Jaheem Smith, 41, was off-duty and at Angry Wade’s at the corner of Butler and Smith streets in Boerum Hill around 3 a.m. Saturday when he spotted the guard struggling with two patrons and tried to help, police said.

The 30-year-old bouncer was trying to escort the irate customers out of the bar when they stabbed him twice in the left side of his torso, cops said.

When Smith stepped in, the enraged pair turned their attention to him — also stabbing him in the torso.

Smith was taken to Methodist Hospital in stable condition. The bar worker was also taken to the hospital with a collapsed lung.

The patrons, identified as 27-year-old Genesis Cano and Andrae Hall, 33, were each charged with attempted murder and multiple counts of assault, cops said.

Police sources said Hall had also made anti-gay statements during the encounter.

Smith, who is recovering at home, began working with the Department of Correction in Dec. 2016 and was most recently assigned to the Eric M. Taylor Center on Rikers Island, a department spokesman said.

“The thoughts of our entire department are with our officer, his family, friends and colleagues,” said Deputy Commissioner of Public Information Peter Thorne. “We are doing everything we can to provide him with any help and support needed as he recovers.”