"While one constable spoke to him, the other went to the police car and retrieved a firearm," Detective Inspector Bruce Scott told the Herald.
"He was then arrested at gunpoint as he tried to drive away. They [the constables] were hugely brave. They made sure that nobody was injured or killed as a result of their brave actions."
Mr Scott said the officers had risked their lives to protect staff, patients and visitors at the hospital - and the community. "It could have gone completely pear-shaped, especially if he'd driven off."
A witness who did not want to be named said the officers were lucky not to be killed.
"They came out of the hospital and had to face the offender unarmed. One officer shouted at the offender and distracted him while the other snuck back to the shot patrol car to retrieve a firearm. It was only out of the co-operation of the offender that the officers were not shot. Had he been there to actually shoot the officers they'd be dead."
The man is expected to appear in the Waitakere District Court this morning.
He first came to police attention at 1pm yesterday when he went to a house on Easton Park Pde in Glenfield and fired two shots inside.
Mr Scott said police were still establishing why the man went to the house and what his movements were between leaving the property and turning up at the hospital.
He said the alleged offender was not injured and it was unclear why he was demanding to see a doctor. The investigation into the incident was ongoing.
A spokeswoman for the Waitemata District Health board said it could not comment on an incident being investigated by police.
A woman was on the way to the hospital with her son in an ambulance when paramedics got the call about the gunman.
They were told the hospital had been locked down, and the ambulance was directed to another part of the building away from the emergency department.
"Police were in the hospital guarding a European (man) and the nurse told us that there was a shooting, that a gunman... had fired shots at the police car," she said.
"We then saw the police car with a shattered passenger front window and the boot of the car was up, there were yellow markers and a police officer taking photos."