Picture: Ivandrei Pretorius/Pexels

Sydney - A gunman has been shot dead after an hour-long shooting spree in western Sydney on Wednesday night, in which he opened fire on a residential home and two police stations.

New South Wales (NSW) Police declared the shooting at a police station "a critical incident," which left multiple officers with injuries, including one who is being treated in hospital for a pellet wound to his head.

Police said a number of shots were fired into the front of St Marys Police Station on Wednesday night. 

Shortly after, the same gunman, armed with a pump-action 12 gauge shotgun, fired a number of shots at police officers at Penrith Police Station. 

Police returned fire, fatally injuring the man who died at the scene, NSW Police said in a statement overnight. 

The two shootings are linked to an earlier incident where shots were fired into a suburban home in the western Sydney suburb of Marayong, police said. 

Local media identified the gunman as 32-year-old bodybuilder Daniel King. Reports said the suburban home belonged to his estranged girlfriend, who is seven months pregnant with King's child.

NSW Deputy Police Commissioner Jeff Loy said officers had "no choice" but to return fire.

"This is a very unusual event and his criminality was extreme," Loy told Sydney's 2GB radio on Thursday.

dpa