The union for longshoremen along the East Coast and Gulf of Mexico has agreed to extend its contract for 30 days, averting a possible strike that could have crippled operations at ports that handle about 40 percent of all U.S. container cargo, a federal mediator announced Friday.