Don't be dumb just get a boat and shoot it from there. If it catches you stab it with a spear or pike it's your only hope. Also don't try to out swim, unless you are level 100 and you have a sick water creature. :)
Stay on your raft! As long as you don’t put even a single toe in the water, they won’t even know you’re there. Learned this after having a panic attack of a Meg being right underneath my raft. Same thing with any dinos you have on your raft.
I once encountered two megalodons in the shallow water of herbivore island, I just shot at him with tranquillized arrows while thinking that I shot him with normal arrows. He didn’t attack or anything and after a while I noticed that he was unconscious. Tamed him and he didn’t even attack