Harvesting energy from the environment offers the promise of clean power for self-sustained systems1,2. Known technologies—such as solar cells, thermoelectric devices and mechanical generators—have specific environmental requirements that restrict where they can be deployed and limit their potential for continuous energy production3,4,5. The ubiquity of atmospheric moisture offers an alternative. However, existing moisture-based energy-harvesting technologies can produce only intermittent, brief (shorter than 50 seconds) bursts of power in the ambient environment, owing to the lack of a sustained conversion mechanism6,7,8,9,10,11,12. Here we show that thin-film devices made from nanometre-scale protein wires harvested from the microbe Geobacter sulfurreducens can generate continuous electric power in the ambient environment. The devices produce a sustained voltage of around 0.5 volts across a 7-micrometre-thick film, with a current density of around 17 microamperes per square centimetre. We find the driving force behind this energy generation to be a self-maintained moisture gradient that forms within the film when the film is exposed to the humidity that is naturally present in air. Connecting several devices linearly scales up the voltage and current to power electronics. Our results demonstrate the feasibility of a continuous energy-harvesting strategy that is less restricted by location or environmental conditions than other sustainable approaches.