Fish obtain oxgen that is dissolved in the water. This occurs via the gills. Gills are feathery structures inundated with blood vessels which allow for a large surface area in contact with the oxygen present in the water. The gills are thin and moist which is ideal for a respiratory structure. In bony fish, an operculum covers the gills and can be used for pumping water across the gills. Sharks don't have this bony gill cover and rely on water flowing into the mouth and across the gills. They must swim to keep breathing. In Osteichthyes or bony fish, at the gills a countercurrent flow occurs to allow the most diffusion into the blood. As deoxygenated blood flows across the gill one way, oxygenated water flows the opposite way. There is a difference or concentration gradient that is established which allows for the most diffusion into the circulating blood. This is not true of Chondrichthyes or cartilaginous fish because they don't have a bony operculum to aid in water being pumped across the gills. Fish also rely on the nervous system in respiration as the brainstem contains nerve cells that establishes a respiratory rhythm.
Contraction of the mouth muscles lowers the floor of the mouth lowering its atmospheric pressure. Water (with dissolved oxygen) moves into the mouth and at the same time the operculum remain closed.
The mouth then open and the operculum muscles relaxes; causing them to bulge open; this increases the volume but lowers the pressure in the gill region.
Water from the cavity moves into the gill region due to the reduced pressure; and bathes the gill filaments. Oxygen diffuses into the blood capillaries due to its high concentration in the gill region than the blood capillaries; it combines with hemoglobin and is transported as oxyhaemoglobin to the respiring tissues.
Carbon dioxide which is of higher concentration in the blood than the gill filaments diffuse into the gills and is exhaled through the water that moves out when the operculum opens.