NEW YORK — Stocks returned to record levels on Wednesday as a rebound in oil prices boosted energy stocks. The stock market also gained after the completion of midterm elections that saw Republicans take control of the Senate.

The direction of the stock market has been dictated by swings in the price of oil this week. Energy stocks plunged on Monday and Tuesday on reports that Saudi Arabia was cutting prices for U.S.-bound crude. On Wednesday, oil rebounded on a smaller-than-expected increase in overall U.S. supplies.

Devon Energy was the biggest gainer in the Standard & Poor’s 500 index after it reported record oil production late Tuesday and said that its third-quarter earnings more than doubled to $1.02 billion. The results were better than Wall Street analysts had forecast.

The stock market has returned to record levels after a sharp slump last month. The rebound has been fueled by a combination of rising corporate earnings and evidence that the economy is maintaining its gradual recovery.

“We’re within the midst of a secular bull market right now, and I do believe the general trend right now in the U.S. stock market is going to be upward,” said Kevin Mahn, President and Chief Investment Officer at Hennion & Walsh Asset Management.

The S&P 500 rose 11.47 points, or 0.6 percent, to 2,023.57. That surpassed the previous record of 2,018.05 set on Friday. The Dow Jones industrial average gained 100.69 points, or 0.6 percent, to 17,484.53. The index is also at an all-time high. The Nasdaq composite fell two points, or less than 0.1 percent, to 4,620.72.

Investors also assessed the impact of the midterm elections.

America awoke Wednesday to sharper dividing lines in an already divided government. Republicans gained control of the Senate and strengthened their hold on the House in a wave of Election Day victories late Tuesday. Republicans racked up Senate victories in seven states, including GOP-leaning Arkansas, Montana, South Dakota and West Virginia.

Many analysts pointed out though that a divided government isn’t necessarily negative for the stock market.

Evaluating data going back to 1946, analysts at S&P Capital IQ found that the stock market had its best returns when a Democratic President was opposed by a unified Republican Congress. In the eight years when that combination was in place the S&P 500 index gained an average of 15.1 percent.

The worst returns occurred when a Republican president was working with a split Congress. In that scenario, stocks rose an average of just 3.5 percent a year.

Despite this week’s events in Washington, what matters more for investors when evaluating companies is the strength of their balance sheets and their earnings potential, said W. Janet Dougherty, a global investment specialist based in Chicago with J.P. Morgan Private Bank.

“In the near-term what happens in Washington shouldn’t deter you, or impact how you’re investing,” Dougherty said. “It really does come down to fundamentals.”

Investors also got some encouraging news on hiring on Wednesday.

U.S. companies added 230,000 jobs in October, payroll processer ADP said Wednesday. That’s the most in four months and a sign that businesses are still willing to hire despite signs of slowing growth overseas.