A pair of Alameda County sheriff’s deputies were lucky to be alive after their job of serving an eviction notice took a frightening turn at an Oakland home Tuesday.

The deputies were at a rear door of a two-story West Oakland residence, serving the eviction notice around 11 a.m. at a lower unit, when a massive explosion blew out the wall on them and a locksmith, and sparked a fire that ripped through the building, authorities said.

Once firefighters extinguished the blaze at 14th and Peralta streets at about 11:30 a.m., they made the grim discovery of a body inside, officials said. An investigation was under way to determine whether the man died as the result of the fire or perished earlier.

It appears the fire was caused by a natural gas explosion, said Oakland Fire Chief Teresa Deloach Reed. A gas line from the water heater appeared to be disconnected, she added.

The two Alameda County sheriff’s deputies were taken to Highland Hospital with moderate injuries, said Sgt. J.D. Nelson, a spokesman for the office. They were being kept overnight to undergo tests for concussions.

Other residents of the home, which was separated into three units, were not injured, Nelson said.

Neighbors described the man who died as being in his early 30s and reclusive. Ike Forrest, 68, who rents the upstairs unit with his wife — his son lives in the second downstairs unit — said he was out serving breakfast to the poor when the explosion happened.

“I feel blessed,” he said, standing by the charred wreck of what had been his family’s home for three years.” He said the man who died “knew the landlord was coming to evict him. He knew, and it looks like he wanted to take everyone with him.”

He said the man had “broken a key off in the lock, so they had to drill it out. That might have sparked the explosion.”

His wife, Janice Forrest, said she had smelled gas earlier in the morning and had gotten up to check the stove, but couldn’t find anything wrong.

Hamed Aleaziz and Nanette Asimov are San Francisco Chronicle staff writers. E-mail: haleaziz@sfchronicle.com, nasimov@sfchronicle.com