(CNN) -- A sheriff's deputy and a man who exchanged gunfire with officers on a plaza outside a Tulsa, Oklahoma, courthouse Wednesday were among three people hospitalized, officials said.
A bystander also was shot and wounded near the Tulsa County Courthouse, said Sgt. Shannon Clark of the Tulsa County Sheriff's Office.
The gunman, identified as Andrew Joseph Dennehy, 23, discharged a handgun into the air around 2:39 p.m. (3:39 p.m. ET), officials said. Deputies swarmed to the plaza.
"The suspect waved his gun at the deputies," Clark told CNN. "One round was discharged, and our deputy yelled 'I'm hit.' That's when our deputies returned fire."
The deputy suffered serious injuries to his hands, but they weren't considered life-threatening. A woman was in fair condition, officials said.
A law enforcement official told CNN the suspect was shot in the head and was in critical condition. Authorities said they did not know why the man initially opened fire.
Leland Ashley, a spokesman for the Tulsa Police Department, which is conducting an investigation, said the department had contact with Dennehy previously. He did not know what the circumstances were.
It was not clear whether the bystander was struck by bullets fired by the suspect or deputies.
A fourth person at the scene, a woman, was treated for emotional distress.
Photographs published by the Tulsa World newspaper and CNN affiliate KOTV showed the barefoot suspect, wearing shorts and a T-shirt, before and after he was wounded. They were taken by an employee of a library overlooking the scene, KOTV said.
Undersheriff Brian Edwards said Tulsa police would investigate because the incident was an officer-involved shooting.
"Our deputies did an outstanding job today," Edwards said. "They confronted an armed suspect, and they prevented him from entering the courthouse. I have no idea what the suspect's intent or motive was, but they did not allow him to get in."
The courthouse reopened about an hour after the shooting, county spokesman Michael Willis said.
CNN's Sara Pratley, Carol Cratty and Joe Sutton contributed to this report.