The dramatic events played out on Sunday night, when young Alv Åkerlund Mattsson was at home with his family in Gävle watching television.
Suddenly there was an unexpected knock at the door. Alv went to answer the door only to find his friend and neighbour standing outside in his underwear.
"Alv, there's a fire!" screamed the boy.
Sure enough, smoke was pouring out the neighbours' flat, prompting Alv's family into a panicked frenzy to gather up pets and valuables and get out of the building.
But before heading to safety, Alv remembered the fire extinguisher his family kept in the kitchen. Grabbing the fire extinguisher, Alv then darted across the hall and into the neighbours' burning apartment, much to the surprise of his mother.
"Of course I was worried, but everything was so confusing. I had other children to keep track of so I don't think I really realized what was going on," mother Jenny Åkerlund told The Local.
Battling the thick smoke, the 12-year-old amateur fire fighter made his way to the kitchen where he saw that a frying pan was on fire.
The police said that the fire was burning so fiercely that there was a danger of it raging out of control. Flames were also getting ever closer to the fan connected to the building's central ventilation system, which would have allowed the fire to spread throughout the block of apartments.
But Alv stood his ground, hoisted up the fire extinguisher, and emptied its contents, dousing the flames and causing local police to heap praise on his heroic deed.
"Thanks to Alv's resourcefulness, coupled with the fact that his family had a fire extinguisher at home, Alv was able to save an entire apartment building and save many people's homes," the Gävleborg County police wrote on their Facebook page.
The boy's mother is still reeling over how her son reacted during the harrowing ordeal.
"I'm amazed at how level-headed he was. He really knew what to do," Åkerlund recalled, admitting that the family hadn't done anything special to educate Alv about how to put out the fire.
"But I know they've discussed it in school," she added.
On Monday, Alv was doing fine after having been treated for smoke inhalation.
"He's a little tired, though," Jenny Åkerlund told The Local.