A policeman was killed and another one was injured.
In an all-terrain vehicle, the attackers first attempted to run into the soldiers at a roundabout near the large coastal town of Sousse.
Security units combed the area, surrounded the attackers and managed to kill three of them after a fire exchange, the Interior Ministry said in a statement.
According to the spokesperson for the National Guard, a fourth man was arrested.
The assailants are reportedly living in this area, which is usually one of the most touristic in the country, but little frequented this year, due to the pandemic of coronavirus.
Since the 2015 deadly attacks in Sousse and Tunis, which targeted tourists, the attacks have now targeted law enforcement agents. Last year in June, a policeman was killed and eight others injured in a double bombing in Tunis claimed by the Islamic State group. This new attack, unclaimed, reminds the reality of the terrorist threat in Tunisia, four days after the swearing in of the new government.