SEATTLE — After battling for months with Boeing Co.'s leadership, the company's largest union approved an eight-year contract that trades hard-fought pension benefits for the right to build the 777X airliner — a bitterly fought concession that underscores unions' uphill battle at the bargaining table.

The contract approved late Friday was negotiated not with a bankrupt city or a struggling manufacturer, but with a company that delivered a record 648 planes last year and whose shares traded at all-time highs on the New York Stock Exchange.

It's part of a larger trend for labor unions, which face dramatic declines in membership strength, reduced bargaining power because of right-to-work states and hostile public opinion.

"The fact that Boeing is doing this is going to send a message to other companies — we can now put that on the table," said Leon Grunberg, a University of Puget Sound sociology professor who co-wrote "Turbulence: Boeing and the State of American Workers and Managers."

"Unions are in retreat and they are trying to slow the tide of concessions," he said. "It's a defensive battle to slow things down."

Boeing said the contract concessions were essential to compete financially with longtime European rival Airbus, which plans to deliver the first of its more fuel-efficient twin-aisle jetliners this year. The two companies are neck and neck in the large jet market, with each looking for even the smallest of financial gains over the other.

Boeing, showing it was willing to move the program out of the Puget Sound region, opened a nationwide sweepstakes to find a potential home for the 777X production. Twenty-two states, including California, offered incentive-laden proposals amounting to billions of dollars in case the union deal didn't come through.

The outside offers — combined with the passage by Washington state legislators of the biggest corporate tax subsidy in U.S. history at $8.7 billion — put a heavy burden on the union local to agree on a deal, union leaders said.

When Boeing came to local union leaders with the offer, they flatly turned it down. But they were overruled when the union's national leadership forced a vote.

The outcome highlights the increasing inability of organized labor to confront companies whose wide geographic options translate into formidable bargaining power. At stake for the International Assn. of Machinists and Aerospace Workers were thousands of jobs and union dues in a major manufacturing state that still allows unions to hold sway— at a time when major union-sponsored work stoppages, a measure of union activism, have been in steady decline since the 1970s.

"We faced tremendous pressure from every source imaginable influencing how to vote today," said Jim Bearden, the local union's chief of staff, at a news conference after the contract was approved by just 51% of voting members. "The politicians, the media and others — who truly had no right to get into our business — were aligned against us and did their best to influence our peoples' vote."

The international machinists District 751 represents more than 31,000 of about 82,500 Boeing workers in Washington state.

"In the larger context, there were some important gains that the machinists won long term, specifically at least 8,000 machinist union jobs at Boeing and possibly as many as 20,000 jobs in the region," said Harley Shaiken, a prominent union expert and professor at UC Berkeley. "In this global context, to have the most advanced manufacturing sited in a unionized setting is an important victory — that came at a high cost."

At issue was a new contract that would convert traditional pension plans for newly hired machinists to a 401(k) type of retirement program. That drew fire from many union members who felt that acquiescing on pension plans was a line that could not be crossed.

Just one day before the vote, several hundred union members rallied at the local union hall in suburban Seattle. They waved signs urging "Vote No," "Stop the War on Workers" and "Don't Sell Your Soul!" Firefighters, Teamsters and other union members crowded into the meeting hall to show their support for the machinists.

"This is the fight of our lives," said a local union leader, Wilson Ferguson, as the crowd in the hall cheered. "This is the front line of the labor movement right now. Thank you for coming out and supporting us."

Boeing officials said the vote signified a new era of cooperation with the workers. "Thanks to this vote by our employees, the future of Boeing in the Puget Sound region has never looked brighter," Ray Conner, Boeing Commercial Airplanes chief executive, said in a statement. "This will put our workforce on the cutting edge of composite technology, while sustaining thousands of local jobs for years to come."

Nationally, support for organized labor has been slipping. Union membership has plummeted to 11% of the U.S. workforce from 35% in the 1950s.

Philip M. Dine, an expert on unions and labor and author of "State of the Unions," said labor often didn't do a good enough job of persuading the broader public what's at stake.

"People see the rising income inequality and the struggling middle class, they see all that," Dine said. "They also see labor's declining numbers and declining strength and shrug their shoulders. Labor needs to connect the dots, show why a strong labor movement is in everybody's long-term interest."

According to the National Conference of State Legislatures, 21 states introduced right-to-work measures during their 2013 legislative sessions. Such rules allow most workers to refuse to join unions even if their workplace is unionized.

After a bitter strike in Washington state in 2008 that cost Boeing billions of dollars, the company shipped much of the work on its new 787 Dreamliner to South Carolina, a right-to-work state. Boeing now has more than 7,100 employees there who fabricate, assemble and install systems for rear fuselage sections of the 787.

But Boeing very much wanted to continue building the 777 in the Puget Sound region, where it has the most employees and more than a million square feet of manufacturing space. It is estimated that the 777X program would be responsible for 20,000 direct and indirect jobs.

The work includes fuselage construction, final assembly and fabrication of components such as interiors and wiring. Boeing plans to start production in 2017, with the first delivery expected in 2020.

Boeing probably will continue to seek concessions from the union when the company proceeds with a future new airplane design, said Scott Hamilton, an aviation industry consultant and managing director of Leeham Co. in Issaquah, Wash. After the union vote, he said on his website, "We're going to see another round of efforts to browbeat the union and the state into more concessions or give-backs in exchange for production to be located here."

Boeing was responsible for $70 billion of Washington's $76-billion aerospace industry in 2012.

If there is "one place where skilled manufacturing workers still have jobs with a large corporation in the country, it would be Boeing in the Pacific Northwest," said John Logan, a professor who specializes in labor and employment studies at San Francisco State University.

"Yet what has gone on," Logan said, "was clearly a reflection of both a boldness and militancy on Boeing's part and a reflection of what they saw as vulnerability and weakness on the part of the machinists union."

Seattle-area machinist union members rally against a contract with Boeing that included concessions on pensions. In the end, members narrowly approved it after Boeing threatened to take production of the new 777X airliner to another state.

Anyone following last Friday's epochal vote in Washington state on a union contract at Boeing could tell from the workers' comments in various forums that the key issue wasn't whether the contract was good or bad, or even whether Boeing was a good or bad company to work for.

In a rare demand that Fiat Chrysler Automobiles buy back as many as 193,000 flawed vehicles, the top U.S. traffic safety agency signaled a tougher stance on automakers that don't identify and quickly repair defects.