LEFT: Downtown Los Angeles is seen through a layer of smog. RIGHT: Smoke billows from a coal-powered power plant in China’s Shanxi province. On Nov. 12, the United States and China announced a plan to limit carbon emissions. (Fred Prouser/Reutersr and Peter Parks/AFP via Getty Images)

On Oct. 18, as the haggling on a proposed climate deal was in full swing, Secretary of State John F. Kerry invited China’s top environmental official to a private lunch overlooking Boston Harbor. As they watched sailboats over plates of seafood, Kerry spoke of the harbor’s transformation from the days when the Charles River carried raw sewage.

Once a symbol of ecological blight, the waterway roared back to health after a concerted effort to target the sources of pollution, Kerry told his guest, Chinese senior councilor Yang Jiechi. “This is a small example that shows how these problems can be addressed,” Kerry said, according to an official familiar with the exchange.

The private meeting was described as a key moment in a largely secret 11 / 2-year journey that led to Wednesday’s landmark U.S.-Chinese pact to scale back greenhouse-gas emissions. At a time when relations were strained over a host of economic and policy differences, the two governments found common ground on an issue that had become a priority for Beijing and Washington, although for strikingly different reasons.

The final details of the pact were hammered out in two marathon sessions in the two weeks before the agreement was unveiled early Wednesday by President Obama and Chinese President Xi Jinping. But the momentum for a deal developed gradually over many months, U.S. officials said, as two countries began to see mutual advantages in taking a shared stance on a problem that had become too big to tackle alone.

World leaders on Wednesday praised the pact, which calls for dramatically deeper cuts in U.S. carbon emissions by 2025 and includes a historic agreement by China to cap its rapidly growing carbon emissions by 2030 or earlier.

President Obama and Chinese President Xi Jinping in Beijing on Wednesday announced a plan for curbing pollution. Combined, the two countries make up 45 percent of the world’s greenhouse-gas emissions. (Reuters)

“These two crucial countries have today announced important pathways toward a better and more secure future for humankind,” Christiana Figueres, the executive secretary of the U.N. Framework Convention on Climate Change, said Wednesday.

But while the agreement boosts the prospects for a global climate treaty late next year, former and current U.S. officials said the interest in a bilateral pact was fueled in large part by domestic concerns. China faces growing internal pressure to deal with the worsening problem of urban smog, a byproduct of fossil-fuel burning in a country that is the world’s largest producer of greenhouse-gas emissions. The nation also seeks increasingly to be seen as a major international player in tackling a global environmental problem for which it now bears substantial blame.

For the Obama administration, the pact offers a path to substantial cuts in global carbon emissions without having to win support from a hostile Congress. Opposition to a climate deal was in full display in Washington as a parade of Republican lawmakers attacked the agreement as unrealistic and unfair.

“As I read the agreement, it requires the Chinese to do nothing at all for 16 years, while these carbon-emission regulations are creating havoc,” said Sen. Mitch McConnell (R-Ky), who is in line to become the Senate majority leader in January.

In many ways, the deal represents the culmination of a strategy the administration had pursued since Obama took office: to persuade Chinese officials to commit to carbon reductions even though they are bound by existing U.N. treaties. With prospects for a new U.N. treaty uncertain, Kerry and his deputies intensified their efforts to strike individual deals with China as well as India.

The diplomacy began in earnest in April 2013, as Kerry was preparing for his first trip to China as secretary of state. He summoned some of his key advisers on China and climate change, including the State Department’s top climate official, Todd Stern, and Daniel Russel, the assistant secretary of state for East Asia and the Pacific.

Kerry, a supporter of aggressive action on climate change since his Senate days, pushed his aides to devise a strategy that would bring about significant U.S-Chinese cooperation on climate quickly, said a senior administration official who spoke on the condition of anonymity because he was not authorized to discuss details of the private sessions.

Even if human greenhouse-gas-emissions levels dropped to those of the 1950s, global warming will continue.

“As the two biggest emitters, he said he was convinced that a joint accord could provide momentum for other countries, too,” the official said.

The official said several Kerry aides advised against a hard press with the Chinese. Yet, the visit yielded progress, leading to the creation of a bilateral advisory body, the U.S.-China Climate Change Working Group. A key figure in launching the initiative was Yang, the former Chinese foreign minister who was later elevated to state councilor.

The personal relationship between Kerry and Yang blossomed during a state visit by the Chinese official to the United States last month. Dispensing with the usual State Department discussions, Kerry hosted Yang at his home in Boston’s historic Louisburg Square. The two shared a meal cooked by noted Boston chef Lydia Shire and then listened to a performance by harpist Jessica Zhou, a Chinese American member of the Boston Symphony Orchestra.

That informal dinner was followed by the lunch Oct. 18 at Legal Sea Foods Harborside, a landmark Boston restaurant that sits above the harbor docks. The subject was the environment, and Kerry invited Stern and John Podesta, the White House’s top adviser on climate change. It was during the three-hour lunch that Kerry began to describe Boston’s enormous environmental challenges in the 1960s, when the water was so contaminated by sewage and industrial waste that swimming was banned and anyone eating harbor seafood did so at one’s own risk. The similarities between the harbor’s polluted past and China’s smog-choked cities were patently clear, the senior administration official said.

“It used to be a symbol of everything wrong with the environment,” the official said, summarizing the discussion between Kerry and Yang. “But through smart, persistent government action it is now one of the cleanest in America.”

Less than two weeks later, ­Podesta flew to China to begin working on a final draft of the pact.

A final achievement was a remarkable degree of secrecy. While environmental groups often are told about major initiatives, U.S. environmental leaders learned about the pact three hours before it was unveiled.

And even that was before some key congressional Democrats learned about the plan.

Ed O’Keefe contributed to this report.