MELBOURNE, Australia -- Australian police said on Tuesday that a shootout in which two men died, three police officers were wounded and a female hostage was freed was being treated as a terror attack.

Police were called to an apartment building in the Melbourne suburb of Brighton on Monday in response to reports of an explosion and discovered the body of a man in the lobby. Police tried to negotiate with a gunman in one of the apartments, an official said.

The gunman later left the building and shot three officers before police killed him. Two of the wounded police officers were taken to a hospital, and the other was treated at the scene.

Get Breaking News Delivered to Your Inbox

Victoria state Police Chief Commissioner Graham Ashton said on Tuesday the gunman, who he did not name, had been implicated in a thwarted suicide attack at a Sydney army barracks in 2009.

"We believe that this person was there with those sorts of intentions, albeit we don't know whether it was something planned at this stage," Ashton told Seven Network television.

"We are treating it as a terror attack," he added.

Australian bomb squad police are seen entering the Buckingham Serviced Apartments in Bay Street in Brighton in Melbourne, Australia, on Mon., June 5, 2017. Reuters

Ashton earlier told Nine Network television that police were aware of the gunman "in relation to terrorism matters, albeit some years ago."

"He is someone certainly known to us from his background, but certainly as of yesterday there wasn't anything that we had that suggested that he was planning on embarking on this, that this was anything more than a spontaneous act," Ashton added.

The Islamic State of Iraq and Syria (ISIS) claimed responsibility for the violence.

Ashton said police did not regard ISIS' claim of responsibility as evidence that the violence was planned.

The Seven Network said it had received a phone call Monday afternoon from a distressed woman who said she was involved in a hostage situation.

"We asked her more information, at that point a man came on the same line and said 'This is for IS, this is for al-Qaeda,'" Seven news director Simon Pristel said.

"We asked for more information and that's when he hung up," Pristel added.

The network immediately called police and passed on the details of the call and the man's phone number.

The woman taken hostage was rescued from the apartment and "is safe and well" with investigators, police said.

"Terrorism is one line of inquiry in relation to this matter. It is early days," Crisp told reporters.