Essid, in a statement on his official Facebook page, praised the army and national guard units who had eliminated the "terrorist cell sent in from Libya".
Their killing in a raid on Wednesday evening had "foiled the terrorist operations the cell was planning", the prime minister said.
At least four of the infiltrators were Tunisian nationals, the interior ministry later said, while the fifth was still to be identified.
One civilian was killed by a stray bullet during the assault on a house outside the town of Ben Guerdane near the border. An army commander was also wounded.
Explosive vests, improvised grenades and a large quantity of munitions were recovered from the slain militants, the interior ministry said.
Six foreign passports were also found, it said without elaborating.
Defence Minister Farhat Horchani, questioned in parliament, said a gunbattle between security forces and the suspects lasted more than an hour.
Signup to our newsletter and follow us on Facebook and Twitter!
Troops had been on alert after receiving reports that militants had been slipping across the border this week following a US air strike on an Islamic State (IS) jihadist group training camp in Libya on February 18 targeting a senior Tunisian commander.
Tunisia has built a 200-kilometre (125-mile) barrier that stretches about half the length of its border with Libya in an attempt to keep out militants.
Deadly attacks by IS on foreign holidaymakers last year, which dealt a devastating blow to the country's tourism industry, are believed to have been planned from Libya.
Last month's US strike on the IS training camp outside the Libyan city of Sabratha targeted the suspected mastermind of two of the attacks, Noureddine Chouchane.
Washington has said Chouchane was likely killed along with dozens of other militants, and that the strike probably averted a mass shooting or a similar attack in Tunisia.
Britain announced Monday it was sending a team of around 20 soldiers to Tunisia to train troops patrolling the border with Libya.
Thirty Britons were among 38 foreign holidaymakers killed in a gun and grenade attack on a beach resort near the Tunisian city of Sousse last June.
And last March, jihadist gunmen killed 21 tourists and a policeman at the Bardo Museum in Tunis.
According to a UN working group on the use of mercenaries, over 5,000 Tunisians, mostly aged from 18 to 35, have travelled abroad to join jihadist groups, especially in Syria, Iraq and Libya.