PARIS — Three young men plotted an attack on a French military base after receiving orders from an Islamic State group contact in Syria to strike in France, prosecutors said Friday.

The accounts investigators say they gave underscore the role of the Islamic State organization's savvy social media machine in recruiting Western youth. All three had high school diplomas and quickly radicalized watching grisly IS group videos, the prosecutor's office said.

The men, arrested Monday, went before an investigative judge Friday. The prosecutor's office opened an investigation June 23 on suspicion they were preparing terrorist acts to harm people.

More than 2,500 potentially radicalized youth have been flagged in France by worried families, Interior Minister Bernard Cazeneuve said this week, and 1,850 others have traveled to Syria or are trying to.

The prosecutor's statement said the three men told investigators they planned a late December or early January attack on the Mediterranean military post Fort Bear, where Djebril A., 23, a former Marine, once worked. The others, Ismael K., 17, and Antoine F., 19, said the plan was to decapitate the base chief, which Djebril A. denied.

Djebril A. told investigators he felt he was on a mission for the Islamic State group and wanted to answer the order to attack a site in France, the statement said. He left the Marines in 2014 after less than a year for failure to adapt to military life.

The three intended to travel to Syria but Ismael K. raised suspicions and was questioned in October. A month later — at his mother's request — he was banned from leaving France, the statement said.

The three, who met online, communicated through an encrypted program.

This story has been corrected to show that the men have been arrested but charges have not yet been filed.