BERLIN  Chancellor Angela Merkel’s Christian Democratic Union party suffered a major defeat on Sunday in an election in Hamburg, with preliminary results showing that the opposition Social Democrats had made big gains and would form the next government there.

According to preliminary results as reported by public television channels ARD and ZDF, Mrs. Merkel’s candidate, Christoph Ahlhaus, the incumbent, was decimated in the race for mayor of the city-state, the equivalent of the premier in other German states. Her party’s share of the vote was cut to 21 percent, from 42 percent in the 2008 elections.

The Social Democrats, led by Olaf Scholz, made a big comeback, winning slightly less than 50 percent of the vote, up from the 34 percent in 2008. If the preliminary results stand, the Social Democrats would be able to govern without having to depend on coalition partners.

It was the first of seven regional elections this year, and the conservative Christian Democrats tried to play down the results.