NEW YORK — Dockworkers along the East Coast and the Gulf of Mexico agreed Friday to extend their contract for more than a month, averting a weekend strike that could have crippled major ports from Boston to Houston and bottled up billions of dollars’ worth of cargo.

Talks aimed at reaching a new contract covering the 14,500 longshoremen will continue during the extension, which runs through Feb. 6.

The dockworkers union and an alliance of port operators and shipping lines agreed to the extension after resolving one of the stickier points in their negotiations, involving royalty payments to longshoremen for each container they unload. Details were not disclosed.

Federal mediator George Cohen said the agreement on royalties was a “step forward.”

“While some significant issues remain in contention, I am cautiously optimistic that they can be resolved,” he said.

The contract between the International Longshoremen’s Association and the U.S. Maritime Alliance originally expired in September. The two sides agreed to extend it once before, for 90 days, but it had been set to expire again at 12:01 a.m. Sunday.

As recently as Dec. 19, the president of the longshoremen’s union, Harold Daggett, had said a strike was expected.

A walkout would have crippled the loading and unloading of a vast number of products, including electronics and clothing, and made it more difficult for U.S. manufacturers to get parts and raw materials at a time when the economy is in shaky condition. The ports involved handle about 40 percent of all U.S. container cargo.

A customer dining at Washington’s Oceanaire restaurant noticed an unusual line at the bottom of his receipt: “Due to the rising costs of doing business in this location, including costs associated with higher minimum wage rates, a 3% surcharge has been added to your total bill.”