The Islamic State group claimed responsibility for the siege, in which a man was killed, several police were injured and a woman was held against her will.
Victoria Police Chief Commissioner Graham Ashton said the gunman, believed to be Yacqub Khayre, was known to police and had a long criminal history.
"We are treating it as a terrorism incident," Commissioner Ashton told ABC.
The gunman was shot dead by police, ending the siege which lasted more than an hour.
Mr Ashton said the gunman "had been involved in a terrorism matter up in New South Wales back in 2009".
IS published a statement via its Amaq propaganda arm, which said the attack in Melbourne was carried out by one of its "soldiers".
Police have not named the gunman.
Graeme Hisgrove, who lives next door to the serviced apartments, said police used his backyard during their operation.
"I was out in the backyard and I heard a large bang, and when I went out on the street to see what was going on, all the police were there and told us to get back in the house," he said.
"I ran back into the house and next thing the Special Operations Group turned up and went through the house and then staked out on our boundary.
"We were just in the front room of the house and all the rapid fire started, so we all hit the deck on the floor and just didn't know what was going on."
Three officers were also injured when they stormed the building.