Oxygen is essential for metabolism of animals and is a vital component of their natural habitats. Hypoxic conditions in tissue, when oxygen levels are lower than normal, change a variety of cellular processes, while environmental hypoxia can have physiological and behavioral effects on the whole animal. Larval zebrafish respond to oxygen deprivation with a characteristic set of physiological changes and motor behaviors, making them a convenient vertebrate model to study hypoxia responses. However, to date, hypoxia studies in zebrafish are limited by the existing experimental setups, which only impose hypoxia on a scale of minutes to hours. Here, we present a microfluidic system, which makes it possible to expose spatially confined unanesthetized zebrafish larvae to a broad range of hypoxic and normoxic conditions and to switch between different oxygen concentrations in the medium around the larvae on a 2 second timescale. We used the system to observe different behavioral responses of zebrafish larvae to three levels of rapidly imposed hypoxia. Larvae increased their rate of body movements in response to the strongest hypoxia and increased their rate of pectoral fin beats in response to all levels of hypoxia. Importantly, the behavior of the larvae changed within 15 seconds of the changes in the oxygen content of the medium. The proposed experimental system can be used to study the behavior of zebrafish larvae or other aquatic organisms exposed to other water-dissolved gasses or to different temporal patterns of oxygen concentration. This system can also potentially be used for testing the effects of genetic modifications and small molecule drugs and for probing neural mechanisms underlying various behaviors.