They were responding to an emergency call in the town of Webster in New York state on Monday morning.
The blaze broke out just before 06:00 local time and officers had to evacuate nearby residents in an armored car.
A gunman was later found dead at the scene, the police said.
The man was 62-year-old William Spengler, Webster Police Chief Gerald Pickering told media.
William Spengler appeared to have shot himself in the head, Gerald Pickering said.
He had previously served a 17-year jail sentence after being convicted of killing his grandmother.
William Spengler’s sister is unaccounted for and police fear she may have died in the fire, which engulfed seven houses.
The two dead firefighters were named by police as Tomasz Kaczowka and Mike Chiapperini.
Gerald Pickering told reporters: “It does appear it was a trap.
“These people get up in the middle of the night to go put out fires; they don’t expect to be shot and killed.”
The two injured firefighters were named as Joseph Hofsetter and Theodore Scardino.
They are being treated for gunshot wounds at the Strong Memorial Hospital and are expected to recover.
Another passer-by was also injured in the shooting.
Police spokesmen said the area was “an active crime scene” but that no more shooters were believed to be present.
Roger Vercruysse, described as a friend of William Spengler, was quoted by the Associated Press as saying that the shooter “couldn’t stand” his sister, who lived with him.
Roger Vercruysse said that William Spengler “loved his mama to death”, adding that he “went crazy” after she died in October.
Two of the firefighters had arrived in a fire engine and two in their own vehicles, police said. One wounded man managed to escape but the others were pinned down until the armored car could be sent in.
Police evacuated residents and firefighters were then able to return to tackle the blaze.
Chief Gerald Pickering said: “Webster is a tremendous community. We are a safe community, and to have a tragedy befall us like this is just horrendous.”
New York Governor Andrew Cuomo said in a statement: “All of our thoughts and prayers go to the families and friends of those who were killed in this senseless act of violence.”
New York Attorney General Eric Schneiderman said: “The contributions made by the fallen and injured officers in Webster will never be forgotten.
“As this investigation unfolds, we stand with our partners in law enforcement to ensure that lethal weapons are out of the hands of dangerous people, so that the brave New Yorkers who risk their lives every day to protect us are not exposed to additional danger.”
There were also two separate incidents of on-duty police officers being shot dead on Monday.
A policeman was killed in the city of Houston, Texas, after the driver of a car he pulled over opened fire on him.
In the midwestern state of Wisconsin, a policewoman on early morning patrol was found shot dead in the town of Wauwatosa.
The debate on gun violence in the US was rekindled earlier this month by the shootings at a school in Newtown, Connecticut, which left 20 children and six adults dead at Sandy Hook Elementary School.
It was one of the worst mass shootings in American history.
“There’s a heightened awareness to this kind of violence in light of what happened in Connecticut,” said Maggie Brooks, leader of the local administration in Monroe County, the area which includes Webster.
“We have first responders and we have families who are in pain and crisis today and we need to, as a community, keep them in our thoughts and prayers,” Maggie Brooks said, adding that it was a “very, very difficult day”.
President Barack Obama has promised to push for action on gun control while the National Rifle Association (NRA) has called for armed security in all American schools.
6aEmeUuTTAAThe US House Ethics Committee has voted to release its report on former Republican Representative…
ABC News has agreed to pay $15 million to President-elect Donald Trump to settle a…
South Korea’s parliament has voted to impeach President Yoon Suk Yeol over his failed attempt…
Israeli war planes have carried out more than 100 air strikes in Syria on December…
President-elect Donald Trump has threatened to impose 100% tariffs on the BRICS countries if they…
Syrian troops have withdrawn from the city of Aleppo following an offensive by rebels opposed…