Thirteen other firefighters were injured in the blaze, and several police officers also were taken to hospitals. Some residents had to be rescued from the upper floors of the four-story apartment building in the Back Bay neighborhood, but none was hurt, city officials said.
"Today's a sad day for the city of Boston," Mayor Marty Walsh said. "We lost two heroes here today."
The firefighters were identified as Lt. Edward J. Walsh, a 43-year-old father of three who had almost a decade of experience, and firefighter Michael R. Kennedy, a 33-year-old Marine Corps combat veteran who had been a firefighter for more than six years.
"My heart and my condolences go out to the families of the firefighters lost in the line of duty today, as well as to the entire Boston Fire Department," Gov. Deval Patrick said in a statement. "This terrible tragedy reinforces how we must be grateful every single day for the brave men and women who put themselves in danger day in and day out to keep us safe."
Deputy Fire Chief Joseph Finn said the fire appeared to have started in the basement but moved quickly through the building. The cause wasn't known, but he said all indications are that it was accidental and that it was the wind that caused the fire to spread through the building so quickly. Firewalls stopped the fire from consuming adjacent buildings.
"In 30 years I've never seen a fire travel that fast, escalate that quickly and create such havoc in such a short period of time," Finn said.
He said Walsh and Kennedy had gone down inside stairs into the basement, and he assumed that a front window broke out and blew the fire back at them. They called a mayday within two or three minutes of entering the building. Kennedy was found about 30 minutes later and was pulled from the building but was pronounced dead at a hospital. Walsh's body was recovered later.
Some of the other firefighters were injured when they were blown down stairs by a backdraft explosion caused by the wind, Finn said.
Major thoroughfare Storrow Drive was shut down for a time, and people were asked to stay out of the area until Thursday morning. The mayor's office designated the nearby Boston Public Library as a center for people displaced or otherwise affected by the fire to get help.
Despite wind gusts of up to 45 mph and cold temperatures, people gathered to watch firefighters work from outside the building, which was still burning Wednesday night.
"The smoke was unbelievable," said Kayla Dasilva, who lives a few blocks away and went with her roommate to see what was happening.
Anna Kosmidou, who lives in the apartment building next to the one that caught fire, said she and other residents were told they could not stay there Wednesday night.
"I'm very, very afraid. I'm still in shock," she said. "They called me at work, and then I ran over here."
The last Boston firefighter killed on duty died in 2009, when the fire truck in which he was riding struck a building after its brakes failed. Two firefighters died in 2007 battling a restaurant fire in the West Roxbury neighborhood.
At Engine 33/Ladder 15, Kennedy and Walsh's station, not far from the fire and in the shadow of the Prudential Center, people stopped by to pay their respects.
Ralph Watson, a middle school principal in Cambridge, left a bouquet of roses outside the station.
"We live just down from where the fire was. It's very sad," he said. "We were standing when they took, I think, one of them by in a stretcher."