Researchers have designed a lithium-ion battery that contains a fire-extinguishing material, which is released if the battery gets too hot.
Flame retardant triphenyl phosphate (TPP) sits inside a shell within the electrolyte fluid. The shell melts when the temperature reaches 150C (302F), releasing the chemical compound.
In tests, battery fires were extinguished in 0.4 seconds.
Lithium-ion batteries power many devices but are a known fire hazard.
The Stanford University research team's peer-reviewed paper has been published by the journal Science Advances.
Previous attempts to incorporate TPP inside batteries without the shell have hampered their performance.
If a lithium-ion battery cell charges too quickly or a tiny manufacturing error slips through the net it can result in a short circuit - which can lead to fire.
In February 2016, the US National Transportation Safety Board issued a warning about lithium batteries in aeroplane cargo, describing them as "a fire and explosion ignition source".
While Samsung has not yet released the results of its investigation into what caused some of its Galaxy Note 7 smartphones to catch fire last year, local reports have suggested it has found that the batteries were responsible.
However, the firm would not confirm that this was their conclusion.
"We understand the need for answers and appreciate your continued patience as well as that of our valued customers, partners and stakeholders," it said in a statement.
"We are working diligently to ensure that we have a comprehensive update and will provide more information in the coming weeks once we have the final report."
Battery technology has been slower to evolve than the many battery-powered devices that rely on it, said Ian Fogg, senior analyst at IHS,
"There is enormous pressure to improve battery tech. It's one of the areas that's holding back mobile devices and a range of other products," he told the BBC.
"Manufacturers have been balancing out consumer demand for longer-lived batteries, and more powerful devices with better graphics and larger more detailed displays, with the sophistication of battery tech.
"It's very difficult to push up the capacity of batteries and there is always a risk that a battery in any device could fail."