Stocks rallied on Wednesday, reversing three days of losses on optimism the European debt crisis might ease after Germany's top court smoothed the way for Berlin's participation in bailout packages.

All major indexes gained as much as 2 percent, and all 10 S&P sector indexes were higher in a broad rally.

European stocks bounced back from a two-year low after the German court rejected lawsuits aimed at blocking the country from joining in to aid Greece and other nations.

But the court said the government must get approval from a parliamentary committee, which could further slow a response. The FTSEurofirst 300 index of top European shares closed up 3 percent.

While a resolution to the issues in Europe is not immediate, this shows that they seem to be on the path of making some progress, said Howard Ward, chief investment officer at GAMCO Growth in Rye, New York. That's a huge positive.

Yahoo Inc (YHOO.O) shares gained 4.3 percent to $13.47 after its chairman, Roy Bostock, abruptly fired Chief Executive Carol Bartz on Tuesday, ending a tumultuous tenure marked by stagnation and a rift with Chinese partner Alibaba.

The Dow Jones industrial average markets/index?symbol=us%21dji>.DJI was up 226.37 points, or 2.03 percent, at 11,365.67. The Standard & Poor's 500 Index .SPX was up 28.01 points, or 2.40 percent, at 1,193.25. The Nasdaq Composite Index .IXIC was up 62.65 points, or 2.53 percent, at 2,536.48.

Financials led the day, with the S&P financial sector .GSPF up 3.8 percent and the KBW Banks index .BKX adding 4.9 percent.

The financials have been pounded mercilessly, and we're starting to get a real bid under their valuation, said Ward, who helps oversee $36.1 billion in assets under management.

Bank of America Corp (BAC.N) rose 5.6 percent to $7.39 and was the top percentage gainer on the Dow after the heads of its consumer banking and global wealth and investment management units left in a management shake-up. Bank of America has lost almost half of its market value this year.

Shares of energy companies, another sector closely tied to economic growth, were also higher. The S&P energy index .GSPE rose 3.2 percent while the price of crude oil rose 3.8 percent.

The CBOE Volatility index .VIX fell 7.6 percent after spiking 9 percent on Tuesday. The index usually moves inversely to the S&P 500.

Darden Restaurants Inc (DRI.N) was the biggest loser on the S&P, falling 3.7 percent to $44.49 a day after the operator of the Red Lobster and Olive Garden chains warned that Hurricane Irene hurt its first-quarter earnings.

Nvidia Corp (NVDA.O) climbed 9.3 percent to $14.40 a day after the chipmaker forecast 2013 sales that topped market expectations.

About 87 percent of stocks traded on the New York Stock Exchange were in positive territory, while 83 percent of the Nasdaq rose.

(Editing by Leslie Adler)