A 12-year-old boy in Australia is fighting for his life after being attacked by a large shark while swimming in the Sydney Harbour.

The boy and his group of friends were jumping off a six-metre rock ledge at Shark Beach, in the Sydney suburb of Vaucluse, when the attack happened on Sunday.

He sustained critical injuries to both legs and is now under intensive care, authorities say. Police praised his friends for promptly pulling the unconscious boy out of the water before rescuers arrived. It was their actions that gave him a shot at survival, a police superintendent said.

Despite its name, shark attacks are rare at Shark Beach - a popular swimming spot.

"The actions of his mates... have been nothing but brave. [It was] a gallant recovery," said Joseph McNulty, who leads the state of New South Wales' marine area command.