Chancellor Helmut Schmidt's Social Democratic Party suffered dramatic losses today in city-state elections in the West German leader's home town of Hamburg.

In a vote that was regarded as a key national test for the beleaguered party, the Social Democrats scored their worst result since 1949 in the northern port city, where they have ruled without interruption for 25 years.

The Christian Democrats, achieving their best showing ever in the city, gained substantially among the working class, which has been traditionally aligned with the chancellor's party, to pull slightly ahead of the Social Democrats.

A left-wing grouping known as the Green Alternative List, which ran on a platform opposed to NATO, nuclear weapons and nuclear energy, also drew from the Social Democrats' traditional support, particularly among young voters. Apparently benefiting from uneasiness about nuclear power plants in northern Germany and pollution of the Elbe River, the party entered the Hamburg legislature for the first time.

The Free Democratic Party, the junior partner in Schmidt's coalition, failed again, as it did in the last Hamburg elections in 1978, to clear the minimum 5 percent mark required for representation.

The election came just four days before Schmidt is due to host a meeting in Bonn of leaders of the North Atlantic Treaty Organization. The chancellor represents a Hamburg constituency in the Bonn parliament, has a home there and is strongly identified with the city.

Sensitive to the election's importance to his own government's future, Schmidt went to unusual length this spring to bring foreign dignitaries to Hamburg--among them French President Francois Mitterrand, Italian Premier Giovanni Spadolini and King Juan Carlos of Spain.

West German political commentators observed tonight that the Hamburg results were likely to push the national coalition of Social Democrats and Free Democrats to an early breakup, possibly by the end of this year.

Since the 13-year-old coalition won reelection in October 1980, the Bonn government has been weakened by strains between the coalition partners, economic and budget problems and dissension in the Social Democratic Party between supporters of Schmidt and left-wing members who have challenged the chancellor's security policy and West Germany's strong alliance with the United States.

Today's election outcome marked the second major defeat at the polls this year for the Social Democrats, following a vote in March for the parliament of the state of Lower Saxony. A third regional election in September in the state of Hesse is widely expected to decide the fate of the Schmidt government.

According to official voting results, the Social Democrats fell to 42.8 percent of the vote, down from 51.5 percent in 1978. The Christian Democrats won 43.2 percent of the vote, up from 37.6 percent.

The left-wing coalition, joining the Greens environmental party and the Alternative List got 7.7 percent compared with 3.5 percent for a similar left-wing group in 1978. The Free Democrats received 4.8 percent as they did in 1978.

In the 120-seat Hamburg legislature, the Social Democrats and Christian Democrats are expected to hold 55 seats each, making composition of the state-government uncertain.

Under Hamburg's constitution, the Social Democrats, led by Mayor Klaus von Dohnanyi, can continue to govern the city with a minority government unless a majority coalition can be formed to replace them. It appeared unlikely that the Greens would join either of the larger parties to form a coalition.

"Helmut Schmidt has lost more than eight percentage points in these elections," declared Helmut Kohl, national chairman of the Christian Democrats. "He is the big loser."

Willy Brandt, chairman of the Social Democrats, acknowledged in a television discussion after the vote that it would have "psychological repercussions" in Bonn.

West German Foreign Minister Hans-Dietrich Genscher, who heads the Free Democrats, voiced disappointment with the outcome, having personally campaigned heavily in Hamburg.