Sounds like you encountered a "rip" [0]; usually letting it take you out and then swimming after the current eases is the safest thing to do. At school (Oceania) we get taught this as part of water safety, but I suppose it would be a foreign concept to many people, particularly those not living near the coast.