Fish gills act as the equivalent of a mammal's lungs by taking in oxygen and releasing carbon dioxide. Oxygen and carbon dioxide travel across small, thin-walled blood vessels in both lungs and gills. In terms of evolution, gills are significantly older than lungs.
While mammals' lungs work with air, which is 200,000 parts per million oxygen, a fish's gills are working with water, which is only up to 8 parts per million oxygen. This means fish struggle to control the flow of salt through the blood vessels in their gills. For a freshwater fish, the challenge is to prevent the loss of salt from its body. For a saltwater fish, the challenge is preventing excess salt from getting into its system.
Another reason fish must work harder to "breathe" is that water is thicker than air and therefore more difficult to process.
Fish gills are actually much more efficient at oxygen extraction than lungs. However, a fish is unable to breathe out of water owing to the fact that the surface area of gills collapse when taken out of water and introduced to air.
Crustaceans, such as crab, lobster and crawfish, and mollusks, also breathe through gills, although theirs are structured slightly differently.