(This June 23 story was corrected to reflect company name is Conning, not Conning & Co in paragraph seven)

(Reuters) - U.S. stocks ended higher on Friday after a last-minute trading spike and a technology sector gain offset weakness in financial stocks and sent the Nasdaq higher, giving it a weekly gain for the first time in three weeks.

The energy sector rebounded and finished the strongest of the S&P’s 11 sectors with a 0.8 percent rise as oil prices came back from multi-month lows.

Bank stocks ended lower even after they passed their annual stress test as some results were weaker than expected and investors focused on a flattening yield curve.

The healthcare rally faded on Friday as investors tried to decipher whether a Senate Republican bill to replace Obamacare, released Thursday, would gain enough support to pass.

The sector closed down 0.1 percent, clawing back some losses after it dropped sharply late in the session when Republican Senator Dean Heller became the fifth U.S. Republican senator to say he would not support a healthcare bill unveiled by his party on Thursday. The sector still closed 3.6 percent higher for the week.

Trading volume jumped just before the close due to FTSE Russell’s completion of the annual refresh of its benchmarks.

“The effect is going to be focused on small-caps but there’s an echo of that in large caps,” said Don Townswick, Director of Equity Strategy at Conning in Hartford, Connecticut, who noted that most rebalance-related trading is around the close.

More than 10.4 billion shares changed hands on U.S. exchanges, well above the 7.2 billion average for the last 20 sessions.

Traders work on the floor of the New York Stock Exchange (NYSE) in New York City, U.S., May 31, 2017. REUTERS/Brendan McDermid

Oil prices edged up Friday after hitting their lowest point since August earlier in the week, but showed an almost 20 percent year-to-date drop as production cuts have failed to reduce oversupply.

Even after Friday’s gains, the energy sector posted its worst weekly decline since September.

The Dow Jones Industrial Average closed down 2.53 points, or 0.01 percent, to 21,394.76, the S&P 500 gained 3.8 points, or 0.16 percent, to 2,438.3 and the Nasdaq Composite added 28.57 points, or 0.46 percent, to 6,265.25.

For the week, the Dow added 0.05 percent, the S&P rose 0.21 percent and the Nasdaq gained 1.84 percent.

Big technology stocks, including Apple, Facebook and Microsoft, were the S&P 500’s biggest boosts on the day and sent up the tech sector 0.7 percent.

The S&P financial index, fell 0.47 percent, with pressure from banking stocks after the stress test results and ahead of the second part of their test due on Wednesday.

“It is a sell-on-the-news effect,” said R.J. Grant, head of trading at Keefe, Bruyette & Woods in New York. “It might get people back to focusing on things like the yield curve.”

Instead, investors favored growth sectors such as tech.

“People are making bets that rates will stay lower for longer and the economy will kind of muddle along and have very tepid growth,” said Grant.

Advancing issues outnumbered declining ones on the NYSE by a 2.14-to-1 ratio; on Nasdaq, a 1.85-to-1 ratio favored advancers.