The French government sacked a top police officer and another resigned today after 4,000 policemen demonstrated in the streets here to back their demand for removal of two senior Socialist ministers.

Prime Minister Pierre Mauroy called for a full investigation of the protest and disciplinary measures against those involved. The Interior Ministry announced that Paul Cousseran, director general of the National Police, was removed and Paris Chief Jean Perier resigned.

A major political row seems likely as Mauroy has accused the principal opposition leader and mayor of Paris, Jacques Chirac, of "exploiting the legitimate emotion of policemen for political ends."

The demonstrations were seen here as a potentially serious new twist to the wave of public protests that have taken place during the past few months involving students, small-business men and doctors.

The immediate pretext was rising anger within the police force after fleeing gunmen killed two agents here this week. But the protest reflects the steadily deteriorating relations between the government and a large section of the police force that resents continuous shake-ups and changes in its command structure.

Today's protests inevitably were compared to those by policemen in 1958, shortly before the fall of the Fourth Republic. The political circumstances are different, however, not least because of the comparative strength of Fifth Republic institutions.

The most recent demonstration by policemen, in 1979 under the center-right administration of president Valery Giscard d'Estaing, was less overtly political than today's--during which the demonstrators demanded the resignation of Interior Minister Gaston Defferre and Justice Minister Robert Badinter.

About 1,000 angry patrolmen marched on the Justice Ministry, flashed victory signs and sang the "Marsaillaise." Policemen assigned to guard the building took off their caps in a show of unity with the protesters.