Short answer: check the water temperature, test ammonia and nitrite, and add surface movement (point the filter outflow at the surface or add an air stone). If ammonia or nitrite are present, do a partial water change.
Check these, in this order
1. Temperature
Warm water holds less oxygen. Practical Fishkeeping warns that a heater stuck on can push the tank well over 86°F (30°C); if the heater light is on and the water is hot, unplug it. LiveAquaria lists high water temperature and poor circulation as a cause of gasping.
2. Ammonia and nitrite
Both damage the gills, so fish can struggle to breathe even in well-oxygenated water. Practical Fishkeeping notes that ammonia makes fish produce extra mucus, which reduces the working surface of the gills. Test at the first sign of gasping; if either is above zero, follow our high ammonia steps.
3. Surface movement and aeration
Oxygen enters the water at the surface. A still surface or a filter that has slowed down means less oxygen gets in. Ripple the surface with the filter outflow or an air stone.
4. Too many fish
An overstocked tank can run low on oxygen because fish and filter bacteria both use it, Maidenhead Aquatics explains. Check your numbers with the stocking calculator.
Is it always a problem?
Maidenhead Aquatics points out that a few fish, such as some livebearers, naturally feed at the surface, and bettas breathe air from the surface as normal. Watch what is normal for your fish. Several fish gasping with fast gill movement is not normal.
If water tests are fine and fish still struggle, contact an aquatic veterinarian: gill parasites and other diseases can cause the same signs.