A trader works on the floor at the New York Stock Exchange as the market shoots higher Wednesday.

NEW YORK — The “fiscal cliff” compromise, even with all its chaos, controversy and unresolved questions, was enough to send the stock market shooting higher Wednesday, the first trading day of 2013.

All the major U.S. stock indexes swelled more than 2 percent in early trading and were up 308 points at the closing bell. The Dow Jones industrial average briefly surged to its biggest gain in six months.

The revelry multiplied across the globe, with stocks throughout Europe and Asia leaping higher.

In the U.S., the rally was extraordinarily broad. For every stock that fell on the New York Stock Exchange, roughly nine rose. Technology and bank stocks rose the most. U.S. government bond prices fell as investors pulled money out of safe-harbor investments.

But for all the euphoria, many investors cautioned that it can’t last long. The deal that politicians hammered out merely postpones the country’s budget reckoning, they said, rather than averting it.

According to them and others, the markets were celebrating Wednesday not because investors love the budget deal that was cobbled together, but because they were grateful there was any deal at all.

“Most people think that no deal would have been worse than a bad deal,” said Mark Lehmann, president of JMP Securities in San Francisco. He called the current package “not too Draconian.”

The House passed the budget bill late Tuesday night, a contentious exercise because many Republicans had wanted a deal that did more to cut government spending. The Senate had already approved the bill.

The late-night haggling was a product of lawmakers wanting to avert a sweeping set of government spending cuts and tax increases that kicked in Jan. 1 in the absence of a budget deal, a scenario that came to be known on Wall Street and Washington as the fiscal cliff, because of the threat it would pose to the fragile U.S. economic recovery.

Wednesday’s market performance gave no hint of the dark clouds on the horizon.

The Dow briefly surged as much as 273 points in early trading. At the close, it was up 308 points, to 13,413.

The Standard & Poor’s 500 was up 24, or 1.7 percent, to 1,450. The Nasdaq composite was up 68, or 2.3 percent, to 3,088.

The yield on the 10-year Treasury note rose sharply, to 1.83 percent from 1.75 percent. Prices for oil and metals including gold, copper and platinum, were up.

The gains persisted despite small reminders that there are still serious problems punctuating the world economy, like middling growth for the U.S. economy and the still-unsolved European debt crisis. The government reported that U.S. builders spent less on construction projects in November, the first decline in eight months. And the president of debt-wracked Cyprus said he’d refuse to sell government-owned companies, a provision that the country’s bailout deal says it must at least consider.