Ships gather off the ports of Los Angeles and Long Beach, California in this aerial photo taken February 6, 2015. REUTERS/Bob Riha, Jr. LOS ANGELES (AP) — Negotiators reached a tentative contract covering West Coast dockworkers on Friday evening, likely ending a protracted labor dispute that snarled international trade at seaports handling about $1 trillion worth of cargo annually.

The breakthrough came after nine months of negotiations that turned contentious in the fall, when dockworkers and their employers began blaming each other for problems getting imports to consumers and exports overseas.

The five-year deal, confirmed by International Longshore and Warehouse Union spokesman Craig Merrilees, still must be approved by the 13,000-member union's rank-and-file. They work 29 ports from San Diego to Seattle that handle about one-quarter of all U.S. international trade, much of it with Asia.

Negotiators for the union and the Pacific Maritime Association, which represents ocean-going shipping lines and the companies that load and unload cargo at terminals ports, began talking formally in May. Their prior six-year contract expired July 1.

The maritime association did not have immediate comment Friday.

After initial signs of progress, in the fall employers publicly charged dockworkers with creating a congestion crisis to gain bargaining leverage by slowing their work rate and withholding the most skilled workers. The union responded that its members were working safely and blamed the jam on broader dysfunction at West Coast ports that predated contract talks, notably a lack of truck beds to tow containers from dockside yards to distribution warehouses.

By January, the maritime association's members stopped ordering night work crews to load and unload ships, saying that smaller groups would focus on clearing the thicket of containers already on the docks. Union members called it an attempt to hurt workers in their pocketbooks; their negotiators soon agreed to the involvement of a federal mediator.

The slowdown-vs.-lockout dynamic was the kind of brinksmanship familiar to past negotiations between two sides with a history of conflict, dating to the killing of dockworkers during the Great Depression. How much responsibility for the congestion each side bears may never be determined, but their animosity magnified the crisis.

Transport trucks line up to drop off their shipping containers at the Port of Long Beach. REUTERS/Bob Riha, Jr. In early February, the CEO of the maritime association publicly warned that if no agreement could be reached, employers would stop calling workers and shut down the ports within days. Weekend and holiday lockouts of many longshoremen followed, though major ports were not fully closed.

Instead, cargo trickled through. Massive ocean-going ships anchored off the coast of Los Angeles and near the ports of Oakland and Seattle — waiting for berths they anticipated occupying after the long haul across the Pacific that instead were taken by ships whose unloading was itself far behind schedule. By mid-February, about 30 ships clustered outside the Los Angeles and Long Beach harbors, with similar scenes in San Francisco Bay and Washington's Puget Sound. The scenes were reminiscent of a 2002 worker lockout that shuttered West Coast ports for 10 days.

A container ship sails beneath the Golden Gate Bridge as it makes its way into port in San Francisco, California REUTERS/Robert Galbraith Though negotiations between the two sides typically involve public theatrics, U.S. businesses grew increasingly antsy as talks ground on. Groups representing retailers warned that some holiday goods might be delayed; thanks to advanced planning, trouble on the waterfront didn't steal Christmas.

Still, there were broader economic repercussions.

Farm exports suffered — McDonald's in Japan, for example, began rationing fries because of a potato shortage. Apple, walnut and hay producers all said they were losing out to foreign competitors. The meat industry tallied its losses in the tens of millions of dollars. Importers of furniture, books, clothing — even Mardi Gras beads — said their products were stuck on the docks. Honda Motor Co. cut production because of a parts shortage. Wal-Mart Stores Inc. warned that Easter goodies could be affected.

Cargo containers sit idle at the Port of Los Angeles REUTERS/Bob Riha, Jr. After a federal mediator couldn't broker an agreement, the Obama administration dispatched Labor Secretary Thomas Perez to oversee talks this week in San Francisco, where both the union and maritime association are based. After a few days, he warned negotiators that if they didn't seal a deal by midnight Friday, he'd haul them back to Washington, where a parade of elected leaders had been imploring resolution.

With so much at stake, outsiders puzzled over why the talks took so long. A summer deal on health care benefits — longshoremen enjoy complete coverage, and the cost of it was expected to be a big sticking point — seemed to portend quick progress. But negotiations stalled on issues including what future jobs would fall under the control of the union, which worries that automation at the ports will erode its membership.

Cargo containers sit idle at the Port of Los Angeles. REUTERS/Bob Riha, Jr. In the end, the disagreement boiled down to the system for resolving allegations of work slowdowns, discrimination and other conflicts at the ports. The union wanted to get rid of the man who arbitrates disputes in Southern California and proposed changes to the arbitration systems that would accomplish that; the maritime association rejected those suggestions — though eventually the two sides found a compromise.

The unpredictability that preceded Friday's agreement could have long-term implications for West Coast ports and their reputation for reliability. With the widening of the Panama Canal and with ports on the East Coast and Gulf Coast investing to attract more ships, some retailers have said they will think hard before depending on ports such as Los Angeles and Long Beach for the smooth flow of cargo.