The reason this is possible is because lungfish have evolved to use both a set of gills and a lung-like organ (hence their name)! In times of drought, a lungfish burrows into the mud and secretes a fluid that all but covers its mouth.
In this way, it prevents itself from drying out and can rely on breathing through its swim bladder, which functions much like a lung. Nevertheless, lungfish are not the only species of fish that can breathe out of water, but they are the best at doing so. In fact, most have such weak gills that they would die if they weren't able to reach the surface!
Learn more about this weird animal from How Stuff Works.