The two said in statements they had agreed to a health-and-safety plan launched by global union federations IndustriALL and UNI Global Union, which represent tens of millions of textile industry workers.
Inditex, the Spanish firm that owns Zara and other major high-street brands, said the deal aimed "to enhance health and safety conditions in the textile industry in Bangladesh by leveraging the commitment pledged by the various players involved in this Asian economy's textile industry".
It said it had communicated to IndustriALL its "resounding commitment to the agreement concerning safety and fire prevention".
H&M, the Swedish high-street fashion giant, said the five-year plan, first launched in 2012, includes appointing an independent chief inspector to "design and implement a fire safety inspection programme that is credible and effective".
It also requires one or more qualified experts to "complete a full and rigorous review of current building standards and regulations" for garment manufacturers.
Activists had set May 15 as a deadline for signing up to the accord.
The full list of signatories has yet to be revealed, but US-based PVH, owner of the Tommy Hilfiger and Calvin Klein brands, and Germany's Tchibo, were among the first to back it, according to anti-sweatshop network The Clean Clothes Campaign.
Monday's announcements came less than three weeks after a nine-storey garment factory complex in a suburb of Dhaka caved in and buried thousands of workers. The death toll from the country's worst industrial disaster on Sunday climbed to 1,126.
Inditex said it had first signed a "framework agreement" with IndustriALL in 2007 "to continually improve labour and safety conditions in textile factories".
There are around 4,500 garment factories in Bangladesh, churning out products for Western fashion labels which sell the clothing at many times the cost price.
The country is the world's second-largest apparel maker and the $20 billion (15 billion euro) industry accounted for up to 80 percent of annual exports last year.
Hundreds of factories which form the hub of Bangladesh's garment industry are to close indefinitely after worker unrest sparked by the accident, the industry's main trade body in the country said Monday.
An Inditex spokesman told AFP the safety agreement would be formally signed at a future date to be set by IndustriALL.
"IndustriALL will publish the details of the agreement in the days to come," the Inditex statement said.
The Clean Clothes Campaign said the two giant companies' commitment to the plan was "monumental news".
It said the agreement will oblige retailers to pay for repairs to make factories in Bangladesh safe.
"H&M and Inditex's decision to sign the legally binding Accord on Fire and Building Safety in Bangladesh is crucial," it said in a statement on Monday.
"Pressure mounts on other key industry players to sign."