The senior detective was rushed to St Vincent's Hospital in a critical condition, and will undergo emergency surgery as doctors battle to save his life.
Police went to the pub to arrest 33-year-old Nick Newman, a suspected child sex offender. Witnesses at the scene reported hearing as many as four gunshots.
The ABC understands the incident was not linked to Australia Day celebrations or protests and witnesses have been encouraged to contact police.
The officer was seen arriving at the hospital surrounded by concerned colleagues while paramedics worked on him.
Assistant Commissioner Mark Walton said the two other officers who were involved in the incident were "traumatised".
Police on Thursday said they were searching for Newman who was known to frequent the Sydney CBD, Redfern and the Nepean area. There was blood everywhere, ' Mackenzie Gibbs said.
Police Association New South Wales President Scott Weber says he feels for the officer and his family and his thoughts and prayers are with the officer and his family.
The westbound lanes of nearby Maroubra Road have been closed because of a NSW Police operation, Live Sydney Traffic tweeted on Friday.
"I saw a man on a stretcher getting carried out of the pub and another man come out of the pub in handcuffs".
A witness Richard Block told Seven News: "I was in the beer garden, having a few beers for Australia Day, and next thing you know I hear all these gunshots".
Police run towards a auto park following the stabbing incident.
"They were pushing us out the door, telling us to get out, it was a crime scene".
One woman said she heard "four of five gunshots".
The homicide squad will now investigate all circumstances surrounding the incident, including the officers shooting the attacker, police said.
"I immediately heard sirens and I went outside to have a look".
Noel Whelan has been staying at the Maroubra Junction Hotel for a few months and was shocked when he was ushered out and into the street this afternoon.
The investigation will be subject to independent review.