Voters in northern Germany cast ballots on Sunday in a local election that will test the strength of the country’s Social Democrats as they try to deny Chancellor Angela Merkel a fourth term.

The Social Democrats are trying to hold onto power in Schleswig-Holstein, where they have governed since 2012. A good showing on Sunday in the region with a population of 2.8 million would reinforce their prospects for challenging Merkel in the nationwide election on Sept. 24.

Social Democratic governor Torsten Albig is defending a slim majority for his governing coalition with the Greens and the left-leaning SSW party, which represents the region’s Danish minority. Polls point to a tight race with Ms. Merkel’s Christian Democrats.

The Social Democrats surged in national polls after Martin Schulz, a former European Parliament president, was nominated as Ms. Merkel’s challenger, but the party’s ratings have since sagged.

The party currently plays second fiddle in a governing coalition headed by Ms. Merkel. Mr. Schulz has a chance to become German chancellor if the Social Democrats come in ahead of Ms. Merkel either by taking over top spot in the current right—left coalition, or by forming a coalition with other parties.

The Schleswig-Holstein vote is a prelude to an election for the regional parliament in North Rhine-Westphalia, Germany’s largest region and home to Schulz, although he is not on the ballot there. The two local elections are the last ballots before the national contest.

Nationally, Mr. Schulz’s nomination had helped the Social Democrats draw roughly level with Ms. Merkel’s conservative bloc, but the latest polls show them trailing by about eight points.