Goldman Sachs beat Wall Street's expectations for second-quarter results Tuesday with outperformance in its investment banking and trading division.

Here's how the company did compared with what Wall Street expected:

Earnings: $5.81 per share vs. $4.89 per share forecast by Refinitiv

Revenue: $9.46 billion vs. $8.83 billion forecast by Refinitiv

Total investment banking revenue: $1.86 billion vs. $1.77 billion projected by FactSet

Goldman's total revenue was down 2% from the second quarter of last year, while investment banking revenue fell 9% year over year, but still beat analysts' expectations. Earnings per share also fell 2.8% from a year ago.

The New York bank notched better-than-expected equities revenue with $2.01 billion in the second quarter, a 6% increase year over year and the second highest quarterly performance in four years. Analysts had been expecting $1.80 billion. The beat was helped by a better market environment with more trading activity compared with the first quarter, the bank said.

Shares of Goldman Sachs closed 1.9% higher Tuesday, bringing its year-to-date gains to 29%.

"Our business performed well and remains solidly positioned for future growth," David Solomon, who took over as CEO in October, said on a call with analysts Tuesday. "While slowing, the global macro backdrop remains broadly constructive."

Goldman Sachs raised its quarterly dividend to $1.25 per share from 85 cents, which was first announced in June after the bank passed the Federal Reserve's annual stress test. Goldman also authorized a $7 billion stock repurchase program, up from $5 billion a year ago.

Net revenues for fixed income, currency and commodities, known as FICC, were slightly below Wall Street's expectations, coming in at $1.47 billion in the quarter vs. $1.52 billion expected in a Refinitiv survey. That reflected "significantly lower" revenue in interest rate products and currencies, and a backdrop of "low levels of volatility and low client activity," Goldman Sachs said.

The bank's assets under supervision hit a record $1.66 trillion — a roughly 10% increase year over year and a 4% jump from the previous quarter, the bank said. Its investing and lending revenues rose to $2.53 billion in the quarter, the best quarterly performance in eight years, the bank said.

"Goldman is progressing fine through what we consider a transition year with the new CEO," Wells Fargo senior analyst Mike Mayo said in a note to clients Tuesday. "It exceeded expectations on the strength of higher stock markets, which helped equity gains."

Goldman posted first-quarter revenue below Wall Street estimates as executives cited tougher market conditions for the firm's trading and investing divisions. But the shares have rallied this year anyway with the stock up 26% this year compared with respective gains of 17% and 12% for shares of rivals J.P. Morgan Chase and Morgan Stanley.

Of the six biggest U.S. banks, Goldman Sachs is the most dependent on Wall Street activities like trading. But the bank — historically known for its list of wealthy corporate and hedge fund clients — also moved into consumer finance three years ago with its Marcus business. Goldman's consumer arm, which offers high-interest savings and personal loans, and has gathered about $48 billion in deposits and made $5 billion in loans so far.

The bank in March announced its first credit card with Apple. On the call with analysts, Goldman's chief financial officer Stephen Scherr said investments in Marcus and the Apple card have resulted in $1.3 billion in total losses. This year, the bank has spent $275 million on those businesses.

"As these businesses scale over the coming years, this drag should not only reverse but become an accretive contributor to the firm's ROE," Scherr said about the businesses on a call with analysts. Goldman Sachs will give a "strategic update" in January and provide new targets with detail on Marcus and the Apple credit card, Scherr said.

— CNBC's Hugh son contributed reporting.

Correction: This story was revised to correct that the premarket trading price was for Tuesday.