The earthquake happened about 09:15 local time (23:15 GMT) on Wednesday at Mansfield, not far from the Victorian state capital.
Prime Minister Scott Morrison said “we have had no reports of serious injuries and that is very good news”.
It was followed by two aftershocks of 4.0 and 3.1 magnitude.
While this is one of Australia’s largest earthquakes in recent years, it has not caused significant damage.
Speaking from the US, Mr Morrison noted earthquakes were uncommon in Australia and they “can be a very, very disturbing event”.
Victoria’s State Emergency Service warned residents to be alert for possible aftershocks.
“If you are located in Victoria, you are in danger. Expect aftershocks, stay away from damaged buildings and other hazards. Avoid driving, except for emergencies,” the authority said.
Quake hit during heart operation
Surgeon Sameer Thakur said he had been performing a heart bypass operation in Geelong, near Melbourne, when the quake hit.
“We’re sort of in the crux of the operation and we just felt the whole operating table move,” he told BBC Newsday.
“Looking around the room, all the IV poles were moving and some of the clamps that we have, they were all shaking.”
He said “fortunately we were at a stage where we could come to a halt” until the shaking stopped, allowing them to complete the surgery.
The Australian Broadcasting Corporation shared a clip of its breakfast TV presenters reacting in the studio as the earthquake hit.
“Is it an earthquake or a structural thing?” presenter Michael Rowland was later shown asking producers. “Let’s go… that was a big one.”
Several high-rise towers and a city hospital were also briefly evacuated, residents reported. Some city tram lines had been suspended due to damage.
South Australia Premier Stephen Marshall said his state had felt aftershocks.
One federal MP, Michael McCormack, said the “ground [was] shaking violently” in Wagga Wagga, NSW.
Large earthquakes are uncommon in Australia because the continent lies centrally on a tectonic plate.
This quake struck at a shallow depth of 10km (6.5 miles), according to Geosciences Australia. It was initially measured at 6.0 magnitude before being revised to 5.9.
Melbourne, the country’s second largest city, is home to about five million people.
The city is currently in lockdown due to a recent wave of coronavirus cases.