Sprinklers are being credited with containing a Sunday afternoon fire at a Fairchild Avenue apartment building, which erupted in the kitchen of one unit but seriously damaged only two of the structure’s 54 apartments.

The fire at 130 Fairchild Ave. was reported shortly before 2:30 p.m. Sunday, and heavy smoke from the kitchen fire filled the building’s second floor, with more smoke infiltrating the third floor, according to the fire report.

However, the building’s sprinkler system prevented the blaze from spreading, fire officials said, although conditions caused carbon monoxide to spike throughout the structure.

Engines 1, 2, 4 and 5, along with Ladder truck 1, were dispatched to the scene, with Assistant Chief Schuyler Sherwood in command at the scene.

“The occupants of the building were extremely lucky that this building had a sprinkler system and that the sprinkler system kept the fire in check. The damage would have been much worse had there not had been a working sprinkler system,” Sherwood said in a statement issued after the incident.

Damage to two apartments in the building left them uninhabitable in the immediate aftermath of the fire, officials said.

Fire units were on the scene for about two hours.