Attorney General Ibrahima Bakhoum said the group had produced explosives and "put the stability of the country at stake".
Tensions are rising ahead of Sonko's trial later this week, in a defamation case that could make him ineligible to contest next year's presidential election.
Sonko and his supporters accuse the government of using the justice system to prevent him from running in February 2024.
The opposition says it will push ahead with demonstrations on Wednesday and Thursday despite a ban by the authorities.
Bakhoum told a press conference that the group aiming to prevent Sonko's trial from resuming planned "to carry out subversive acts and undermine public figures in the judiciary, the state apparatus, in religious circles and the press".
He said they had produced "explosives" and "Molotov cocktails", visiting a market near Guinea to get hold of weapons.
The four people held were arrested for "criminal association, acts and manoeuvres likely to disturb public order, arson", the prosecutor said, adding that 19 others were wanted by the authorities.
One of those arrested claimed to be from the Movement of Democratic Forces of Casamance, a group of separatist rebels, the authorities said.
Senegal, a rare island of stability in the troubled West African region, is seeing another tense week with the resumption of the libel trial against Sonko on Thursday.
The opposition is demanding "the release as soon as possible of all political detainees" and calling for support for Sonko.
Senegal's President Macky Sall has asked the government to take measures to "preserve public order" after previous protests over the trial left at least one person dead.
Sall has denied Sonko's accusation that the judiciary is being used to sideline him from the vote.
The presidential camp accuses Sonko of drumming up anger in the streets in a bid to escape justice.
A close associate and spokesman for Sonko was charged on Monday over the spreading of "fake news", a lawyer said.
El Hadji Malick Ndiaye, head of communications for Sonko's party, was charged and electronically tagged over a message posted on Facebook on March 16 about the conditions under which Sonko was taken to court in Dakar on that day, under heavy police escort.
(FRANCE 24 with AFP)