A blue-ribbon commission had just excoriated Goldman Sachs and other Wall Street banks for fueling the financial crisis. Prosecutors were investigating whether Goldman had misled investors. The company was a whipping boy for politicians looking to lay blame for the crash.

But in spring of 2011, Lloyd C. Blankfein, leading one of the nation’s most reviled companies, found himself onstage with Secretary of State Hillary Clinton, one of the nation’s most admired public figures at the time. And Mrs. Clinton had come to praise Goldman Sachs.

The State Department, Mrs. Clinton announced that day in an auditorium in its Foggy Bottom headquarters, would throw its weight behind a Goldman philanthropic initiative aimed at encouraging female entrepreneurs around the world — a program Goldman viewed as central to rehabilitating its reputation.

Mrs. Clinton’s blessing — an important public seal of approval for Goldman at a time when it had few defenders in Washington — underscored a long-running relationship between one of the country’s most powerful financial firms and one of its most famous political families. Over 20-plus years, Goldman provided the Clintons with some of their most influential advisers, millions of dollars in campaign contributions and speaking fees, and financial support for the family foundation’s charitable programs.

And in the wake of the worst crash since the Great Depression, as the firm fended off investigations and criticism from Republicans and Democrats alike, the Clintons drew Goldman only closer. Bill Clinton publicly defended the company and leased office space from Goldman for his foundation. Mrs. Clinton, after leaving the State Department, earned $675,000 to deliver three speeches at Goldman events, where she reassured executives that they had an important role to play in the nation’s recovery.

The four years between the end of the financial crisis and the start of Mrs. Clinton’s second White House bid revealed a family that viewed Wall Street’s elite as friends and collaborators even as the public viewed them with suspicion and scorn. Those relationships would become a focal point for attacks on Mrs. Clinton’s integrity and independence by Senator Bernie Sanders of Vermont.

And even now, under a barrage of populist taunts from Donald J. Trump, the Republican presidential nominee, Mrs. Clinton faces lingering doubts about the sincerity of her proposals to rein in Wall Street behavior. In June, 60 percent of registered voters expressed concern that her links to Wall Street could prevent her from holding the financial industry accountable, an NBC News/Wall Street Journal poll found.

“Wall Street now conjures up images of corruption, and if you are a person from Wall Street, you have to overcome that,” said Roy C. Smith, a former Goldman Sachs partner who teaches finance at New York University. “One of the big rubs against Hillary now is that she was paid by Goldman to give speeches at Goldman.”

Mrs. Clinton rejects the idea that her loyalties are in doubt. Josh Schwerin, a spokesman, said in a statement on Saturday that Mrs. Clinton was “fighting for tough new rules and more accountability on Wall Street” and to build a more equitable economic system.

Goldman’s links to the Clintons date to the 1990s, when Robert E. Rubin, the company’s co-senior partner, left to join President Bill Clinton’s economic policy team. Economically and politically, it was a vastly different era. Mr. Clinton had embraced deficit reduction and balanced budgets, an approach later called “Rubinomics” after Mr. Rubin, who became Treasury secretary in 1995.

While Wall Street leaned right over all, executives at Goldman gave most of their political contributions to Democrats. Mr. Clinton raised taxes on the wealthy but steered his party to the center on financial issues, helping craft legislation to abolish the Glass-Steagall rules separating commercial and investment banking and exempt some of the products known as derivatives from regulation.

“In the early ’90s, support from the business community and the financial sector was seen as an important credential for Democrats looking to shed the anti-business label that Republicans had been hanging around their necks,” said Howard Wolfson, a top strategist for Mrs. Clinton’s 2008 presidential campaign.

Image

From left, Mayor Michael R. Bloomberg, Senator Hillary Clinton, Lloyd C. Blankfein and Henry M. Paulson Jr. at the groundbreaking of Goldman Sachs’s headquarters in Lower Manhattan in 2005. Mr. Paulson was chief executive of the company at the time.CreditMarilynn K. Yee/The New York Times

The Clintons’ relationships with Wall Street deepened in the 2000s, when Mr. Clinton set up his foundation in Harlem and Mrs. Clinton was elected to the Senate from New York. That brought her in close touch with the big Wall Street firms, a source of jobs and tax revenue for New York — and a leading source of campaign funds for Mrs. Clinton. During her years in Congress, employees of Goldman donated in excess of $234,000 to Mrs. Clinton, more than those of any other company except Citigroup, according to the Center for Responsive Politics.

Along with other New York politicians, Mrs. Clinton worked to obtain federal tax breaks to resuscitate Lower Manhattan after the Sept. 11, 2001, attacks, and those breaks helped Goldman build its new, roughly $2 billion headquarters. When it broke ground in 2005, Mrs. Clinton and other New York officials were on-site.

“Major employers like Goldman Sachs needed to know they had a partner in government,” Mrs. Clinton said at the time.

The firm was her family’s partner outside government, too. Goldman was a lucrative stop on the speaking circuit for Mr. Clinton, who earned over half a million dollars for three Goldman events in 2005 alone. When Mrs. Clinton first ran for president, Mr. Blankfein and his wife, Laura, hosted a fund-raiser at their apartment, ultimately raising more than $100,000 for Mrs. Clinton’s bid.

And when Mr. Blankfein endorsed Mrs. Clinton in 2007, the campaign proudly promoted his support, releasing a statement in which he called Mrs. Clinton “a strong and experienced leader.”

As a spate of foreclosures pushed the country into a recession, Mrs. Clinton, locked in a primary race with Barack Obama, struck a progressive but pragmatic tone. She called for closing the carried-interest tax loophole that benefited financiers and for better oversight of complex financial products. In a December 2007 policy speech at Nasdaq headquarters, she acknowledged her “wonderful donors” in the audience and urged financial executives to voluntarily help struggling homeowners. “Wall Street helped create the foreclosure crisis,” Mrs. Clinton said, “and Wall Street needs to help us solve it.”

Image

Mrs. Clinton at the Nasdaq Marketsite in Times Square in 2007.CreditPatrick Andrade for The New York Times

But when the crash came in 2008, public sentiment turned sharply against Wall Street’s big firms. Goldman stood out for its success amid the calamity, earning hundreds of millions of dollars betting against the housing market. In April 2010, the Securities and Exchange Commission charged Goldman with misleading its investors. At a Senate hearing that month, Mr. Blankfein endured a withering and bipartisan cross-examination.

Mr. Clinton took a different tack. At a conference in Washington the week of the hearing, he said derivatives trading needed better oversight, but he was skeptical of the commission’s charges. “I’m not at all sure they violated the law,” the former president said.

The company was in the midst of an expensive reputation reclamation plan. The centerpiece was an existing program called 10,000 Women, to which Goldman committed $100 million.

“We preferred to demonstrate that we were willing to put skin in the game,” John F. W. Rogers, Goldman’s influential chief of staff, said in a 2009 interview.

In 2011, the State Department created a formal partnership with the Goldman program, a natural complement to Mrs. Clinton’s efforts to mitigate poverty and discrimination against women.

For Goldman, 10,000 Women became a major philanthropic and public relations success. The program’s events attracted influential figures such as the liberal news media entrepreneur Arianna Huffington, who devoted a section of her Huffington Post to the program’s successes.

“I don’t really care why people do good things,” Ms. Huffington said in an interview. “Without a doubt, thousands of women have been helped by this program.”

When Mrs. Clinton left the State Department in 2013, she followed her husband into paid speechmaking. If Mrs. Clinton was concerned about the appearance of taking hefty fees from Wall Street while considering a second presidential bid, she did not show it: In her first year on the circuit, more than a third of her paid speeches were for financial companies.

Each of her three Goldman speeches were private, and Mrs. Clinton has rebuffed requests to release transcripts of them. And at the time, she still embraced Goldman as a partner. In 2014, she appeared at the annual meeting of the Clinton Global Initiative, an offshoot of the Clinton Foundation known as C.G.I., to highlight the 10,000 Women program.

“Thanks to Goldman Sachs and thanks to 10,000 Women for really shining a bright spotlight on what is possible if you believe in and you provide support to women,” Mrs. Clinton said.

It would be one of the last times Mrs. Clinton spoke warmly of the company. Within a year, she was running for president and grappling with the anti-Wall Street wave remaking both parties. Amid her primary fight against Mr. Sanders, Mrs. Clinton energetically defended the Dodd-Frank financial overhaul and called for even broader regulation of Wall Street.

The financial crisis “basically ended the debate within the Democratic Party,” said Austan Goolsbee, a former Obama economic adviser.

Goldman, too, has taken a step back. When C.G.I. held its final conference last week, Goldman sent neither a delegation nor sponsorship cash. Though its employees have contributed hundreds of thousands of dollars to her campaign, none are among Mrs. Clinton’s top bundlers.

On CNBC in February, Mr. Blankfein was asked whom he supported in the campaign.

“I don’t want to help or hurt anybody,” he demurred, “by giving them an endorsement.”