JOHANNESBURG — It’s a surfer’s worst nightmare. There’s a swish in the ocean near your board, a flash of dorsal fin, something large brushes by and the water begins to churn like a supersized blender.

And then you fall into the water.

Renowned Australian surfer Mick Fanning faced his demons at a South African surfing contest Sunday when he fought off a shark at Jeffreys Bay, off the Eastern Cape, in the final of the J-Bay Open surfing championship.

The shark attacked and knocked Fanning, a three-time world champion, off his board. Fanning frantically punched the fish as the other competitor, Julian Wilson, paddled toward him to try to help.

Fanning, miraculously, was unhurt. Rescuers sped up on jet-skis and pulled him and Wilson from South Africa’s cold winter sea.

The World Surf League canceled the competition after the incident.

The surfing final was being filmed live as Fanning, the defending champion, was attacked.

“I was just about to start paddling and I had this instinct that something was behind me. And then the shark came up from behind me and attacked. I got pulled under water and was being dragged under by my leg rope,” Fanning recounted in an interview with Surfer magazine. “Then it kicked me off and I punched it a couple of times. Then my leg rope broke and I was just swimming.

“I was yelling at Julian to get away but he was coming towards me to help. What a legend. Then I was just readying myself for it to come at me again so I turned around, hoping I could at least see it coming. And then before I knew it the boat was there and I was safe.”

Television footage showed the shark attacking, its fin visible above the swirling water, in seas where great white sharks are commonly spotted. At that point a wave passed and Fanning disappeared from sight.

Wilson said the wave also obscured his view of his fellow surfer as he paddled hard, racing to try to rescue him.

“I saw him wrestling it and saw him get knocked off his board. Then a little wave popped up and I couldn’t see him. I thought he’s gone under. It felt like I couldn’t get there quick enough. I literally thought that I wasn’t going to get there in time,” Wilson said in comments to Surfer.