Yes, some fish are simultaneously hermaphroditic, possessing the reproductive equipment of both sexes at one time; a few can fertilize their own eggs.
In some species, called sequential hermaphrodites, an individual can change from male to female, from female to male, or back and forth. Some fish species are entirely female and reproduce by cloning their own DNA, though the process is triggered by sperm from males of closely related species.
Conversion from male to female is called protandry; conversion from female to male is called protogyny.
Sex changes in fish were once thought to be extremely rare. It is now known that changes from female to male occur in at least fourteen families and changes from male to female in at least eight.
In a study of a reef fish called the bluehead wrasse, reported in 1984, sexual identity and behavior were found to vary with the density of the population and the size of the reef.
For example, sometimes a large dominant male fertilized the eggs of many females, and sometimes fish took turns releasing eggs to be fertilized by sperm of other fish, which in turn released eggs for fertilization.
In another wrasse species, a solitary male fertilized the eggs of several females; if the male died, one of the harem became male.
In some hermaphroditic species, the adaptation is thought to help ensure reproductive success when other members of the species are few and far between.
Changes in the sex of the fish are presumed to be influenced by hormones, but the mechanism is not fully understood.