Lt. Vincent Perez, 48, and firefighter-paramedic Anthony Valerio, 53, died from injuries they suffered while battling a blaze at a four-story home at 133 Berkeley Way on Thursday morning.
Perez died later that day, and Valerio succumbed to his injuries on Saturday morning, fire officials said.
A joint funeral for the two men will be held at 12:30 p.m. Friday at St. Mary's Cathedral, located at 1111 Gough St. A vigil for the two men will be held at 7 p.m. Thursday, also at St. Mary's, according to the fire department.
After the funeral, the men will be buried at the Holy Cross Cemetery in Colma.
Perez was a member of the U.S. Marine Corps and served as an Alameda County sheriff's deputy before spending the last 21 years as a San Francisco firefighter.
Valerio spent 27 years as a San Francisco city employee -- 13 with the Department of Public Health and the past 14 as a firefighter-paramedic.
Both men were unmarried and had no children, Fire Chief Joanne Hayes-White said.
The two men were badly burned when objects in the room they were in apparently heated to the point of ignition, a dangerous phenomenon known as a "flashover," fire department spokeswoman Mindy Talmadge said.
A female firefighter suffered smoke inhalation and minor burns while battling the blaze. She was treated at the hospital and released later Thursday.
Fire investigators are still trying to determine what started the blaze.
The San Francisco firefighters' union has established trust accounts for the Perez and Valerio families at the San Francisco Fire Credit Union. Donations can be sent to the credit union at 3201 California St., San Francisco, 94118.
Condolence messages can be sent to Fire Station 26, 80 Digby St., San Francisco, 94131.