A professional surfer has been attacked by a shark, live on television, during a competition.

Australian Mick Fanning was taking part in the World Surf League event in Jeffreys Bay, South Africa, when the shark approached him from behind.

Mr Fanning said he shielded himself with his surfboard and punched the shark in the back, prompting it to swim away.

He was unhurt but the rest of the day's competition was cancelled.