Six people were detained in connection with what police and prosecutors allege was a plan to carry out an attack on Berlin's half-marathon Sunday, German authorities said.

"There were isolated indications that those arrested, aged between 18 and 21 years, were participating in the preparation of a crime in connection with this event," prosecutors and police wrote in a joint statement.

Berlin police tweeted that six people were detained in cooperation with the city's prosecutor's office.

The German daily Die Welt first reported that police foiled a plot to attack race spectators and participants with knives.

The main suspect allegedly knew Anis Amri, a Tunisian who killed 12 people and injured dozens more when he drove a truck into a Christmas market in Berlin in December 2016, Die Welt reported.

AT LEAST 2 KILLED, 20 INJURED AFTER VAN PLOWS THROUGH CROWD IN MUENSTER, GERMANY

One of the apartments Berlin police raided before the race started Sunday was also searched after the Christmas market attack, the newspaper said.

Special police forces detained four men in connection with the race plot, the paper said — different from the six that police reported.

Die Welt reported that the main suspect, who was not identified, had prepared two knives to use in the attack. It also wrote that in one of the searched apartments, dogs trained to find explosives barked when they were taken into the dwelling's basement.

The local daily Tagesspiegel reported that the main suspect had been under observation for two weeks around the clock. After a foreign intelligence service tipped off German authorities that he was planning to attack the half-marathon, police raided apartments and two vehicles in the Charlottenburg and Neukoelln districts of the city.

The half-marathon was being guarded by some 630 police officers, German news agency dpa reported.