Goldman Sachs Group Inc. posted its first quarterly loss in six years as a dismal showing by its trading unit compounded a one-time charge related to the new tax law.

The Wall Street firm posted a $1.93 billion loss, or $5.51 a share, on $7.83 billion in revenue. A $4.4 billion tax-related charge wiped out the firm's entire quarterly profit and more than half of its earnings for the year.

Shares dropped 3%.

Goldman also was the only one of the five large U.S. banks to report quarterly revenue that declined from a year earlier.

Largely to blame was Goldman's fixed-income trading division, which produced half the revenue it did a year ago. This unit posted $1 billion for the quarter -- nearly its output every two weeks in 2009. For the first time since late 2008, the fixed-income trading unit was out-earned by Goldman's underwriting business.

Goldman's fixed-income desk struggled throughout 2017, losing money on oil and gas trades as well as positions in some low-rated corporate debt. Nothing was clicking in the fourth quarter; the firm on Wednesday cited weakness in all four of the division's main pillars, and Chief Executive Lloyd Blankfein cited a "challenging environment for our market-making businesses."

Goldman's traders ruled Wall Street before the financial crisis and basked in its immediate aftermath but have struggled with its lasting effects. Calm markets have sapped demand for their skills and specialized products, while new rules nixed the lucrative bets the bank once placed with its own money.

Overall, Goldman's trading revenue fell 34% from a year ago to $2.37 billion. That is the steepest decline among banks that have reported quarterly numbers so far. Citigroup Inc., for example, on Tuesday said trading revenue dropped 19%.

Goldman executives have acknowledged missteps. Over the past two years, it has cut traders, trimmed bonuses, revamped its sales network, and embraced the type of low-margin, high-volume trades it once deemed too trivial to bother with.

Another key is to win more trading business from corporate clients who hire Goldman for boardroom advice but take their securities business elsewhere.

"We absolutely acknowledge that the business footprint and mix we have is a consequence of choices that we made over time. We know that we need to do better," Chief Financial Officer Martin Chavez said on a conference call with analysts. He said it would take "an order of months" to see those changes, some of which have been underway for more than a year, produce new profits.

Still, another poor quarter is likely to intensify calls for more dramatic changes, including a shake-up of the division's leadership, an idea that has gained steam among top executives in recent weeks.

Mike Mayo, a Wells Fargo analyst known for needling bank executives, pushed for answers.

"It just seems like progress should have been a lot faster than it's been," he said. "It's not news that you're under-penetrated to corporate [ clients]. You have great relationships with CEOs, the people at the top of the house, so why can't you do more business trading with those much further down?"

Meanwhile, the firm is looking for new sources of revenue in steadier businesses like consumer banking and asset management. Both gained ground in 2017; Goldman's asset-management division hauled in $42 billion in new long-term money, while its new consumer-lending platform churned out more than $2 billion in fresh loans.

But both will take years to fill the roughly $10 billion revenue hole opened by Goldman's trading woes -- if they ever do.

Goldman took a $4.4 billion charge related to the new tax law, slightly smaller than expected. Most of the bill is a one-time tax on foreign earnings that Goldman has kept overseas. A smaller chunk comes from revaluing certain tax credits, which are worth less now that the corporate rate has gone down to 21% from 35%.

Excluding the charge, Goldman's net income of $2.26 billion was above the $2.04 billion that analysts had expected. It dropped about 4% from the fourth quarter of 2016, when a trading surge around the U.S. election boosted banks' bottom lines.

Goldman's investment bankers, who arrange mergers and underwrite stock and bond sales, brought in $2.14 billion in the quarter, up 44% from a year ago. The unit's annual revenue of $7.4 billion was its second-best on record, aided by gains in debt underwriting, a newer focus for Goldman, and the continuation of a historic M&A boom.

With fewer companies choosing to go public -- particularly within the crop of highly valued Silicon Valley startups that Goldman has courted, angling for IPO mandates -- the bank is leaning more heavily on mergers, debt underwriting fees and secondary stock sales, which all rose.

The firm's asset-management arm, which runs mutual funds and private investment vehicles, reported $1.66 billion in revenue, up 4% from a year ago. Assets under supervision -- a figure that includes money managed in the firm's own branded funds as well as invested on behalf of clients in outside products -- edged up slightly to $1.49 trillion, though the business is still dwarfed by fast-growing giants like BlackRock Inc. and Vanguard Group

Goldman said it expects $130 million in losses on a single troubled loan to an executive of Steinhoff International, a South African retailer in the midst of an accounting scandal.

Other banks including Citigroup Inc. and JPMorgan Chase & Co. have reported nine-figure losses on the same loan, which was spread widely among international banks.

Goldman's stock price rose sharply in the months following the 2016 election, but bounced sideways for most of 2017. It finished the year up about 5%, the worst-performing of the largest U.S. banks.

Write to Liz Hoffman at liz.hoffman@wsj.com