Sex change is a rather common phenomenon among aquatic animals, but only a few have been reported to change sex in both directions. In laboratory experiments we demonstrated that the coral goby, Paragobiodon echinocephalus, changed sex in both directions with the same likelihood. When the goby lost its mate in the field, it preferred changing sex in either direction over moving a long distance in search of a heterosexual mate. Change in social rank, which is likely to occur in many other hermaphroditic fish, corresponded exactly with the direction of sex change. This constitutes a new condition for the evolution of both-ways sex change among plants and animals.