A driver rammed a car into a Christmas market in the eastern German town of Magdeburg, leaving at least two dead and more than 60 wounded, according to local officials, in a setback for local security agencies which had recently warned about a growing risk of terror attacks.

The suspect, a 50-year-old doctor from Saudi Arabia who had been living in Germany legally since 2006, had been detained, Reiner Haseloff , state premier of Saxony-Anhalt, told journalists on the scene. One of the casualties was a small child, he said.

It was too early to tell whether the incident, which took place just after 7 p.m. local time, was a terrorist attack, Haseloff added, “though there are certainly elements pointing in this direction.”

Other details suggested the more complicated picture of a man deeply critical of Islam and who felt persecuted by German authorities.

The Saudi national had arrived in Germany in 2006 as an asylum seeker, arguing that he fled a society built around a strict version of Islamic law, according to a senior German security official familiar with the investigation. He obtained refugee status and later received permanent residence in the country, where he started working as a doctor and psychotherapist. He lived in the town of Bernburg.

The man rose to prominence in the small Saudi community in Germany as an anti-Islam and women’s rights activist. He ran a website and several social-media channels warning about the dangers of Islamization and advising prospective asylum seekers, the German security official said. The man posted frequently about what he said was the persecution of women in the Middle East.

He had also shared pro-Israel content since the Oct. 7 attack, as well a support for Germany’s anti-immigration AfD party.

In his recent social-media posts published days before the attack he claimed the German government was promoting the country’s Islamization, and accused authorities of censoring and persecuting him because of his critical views of the religion. On his website, he warned prospective refugees to avoid Germany because of what he said was its government’s tolerance of radical Islam.

A social-media video verified by Storyful, which is owned by News Corp, the parent company of The Wall Street Journal, showed sped-up footage of a car driving through a large group of pedestrians in a narrow alley lined by market stalls. Another unverified video showed numerous people lying on the ground around the market located in the center of the state capital.

While the motives for the attack remain unclear, it revived painful memories for Germans, coming one day after the anniversary of a 2016 terrorist attack in Berlin , in which a rejected Tunisian asylum seeker drove a stolen truck through a Christmas market in the center of the capital, killing 13 people.

“Currently, extensive police operations are taking place at the Magdeburg Christmas market. The Christmas market in the city center is closed,” the Magdeburg police wrote on the X social-media platform.

Chancellor Olaf Scholz would visit the scene of the attack on Saturday, Haseloff said.

“These are very distressing news from Magdeburg,” wrote Friedrich Merz , chairman of the center-right Christian Democratic Union, who is leading in polls ahead of next February’s general election . “My thoughts are with the victims and their families. I thank all emergency responders who are taking care of the injured on site.”

Since the Dec. 19, 2016, attack in Berlin, Christmas markets have taken place under heightened precautions, with security guards often controlling bags at the entrance and bollards blocking access for vehicles.

Haseloff said the suspect was being questioned and wouldn’t comment on his motives. The man, who drove a rented BMW through the market, was thought to have acted alone, Haseloff added, saying residents faced no further danger.

The Saudi national doesn’t fit the profile of the suspects—radicalized youth from Syria, Afghanistan or Central Asia—in most recent terror attacks and whom security agencies had been warning about in recent months.

Yet if confirmed as a terror act, the incident is likely to influence the coming electoral campaign, which has focused on Germany’s economic weakness in recent weeks.

The event could rekindle a debate about immigration and security that flared up in August after a suspected terrorist attack by a Syrian asylum seeker in August that left three dead.

Merz’s CDU and the AfD have called for a drastic reduction in immigration. Germany is by far the largest destination for asylum seekers in the European Union. The country registered 236,399 asylum applications between January and November, according to official statistics.

“The images out of Magdeburg are shocking! My thoughts are with the survivors and the wounded,” wrote AfD chairwoman Alice Weidel on X. “When will this madness come to an end?”

Write to Bertrand Benoit at bertrand.benoit@wsj.com and Bojan Pancevski at bojan.pancevski@wsj.com