The revelation confirms repeated fears that the strong presence of the Islamic State group in Tunisia's chaotic neighbor has become a direct threat to the country, the only democracy to emerge from the Arab Spring uprisings.
"It has been confirmed that the attacker trained in Libya with weapons at the same period as the Bardo attackers," said Rafik Chelli, the secretary of state for the Interior Ministry. "He crossed the borders secretly."
Previously authorities had said there was no evidence he had left the country.
Sabratha is also the site of famed Roman ruins. It is one of several places in Libya where radical Islamic groups, like IS which claimed responsibility for the beach attack, have training camps.
More From This Section
Some 3,000 Tunisians have left to fight with radical groups in Syria and Iraq, usually via Libya where they received training. Increasingly, however, they have stayed in Libya before returning to carry out attacks in Tunisia. Tunisia's most well-known Islamic radical Seifallah Ben Hassine, fled to Libya in 2013 taking many supporters with him into exile.
President Beji Caid Essebsi revealed this morning that heightened security measures had been scheduled to be put in place just days after the beach attack.
"It is not a perfect system, it is true we were surprised by this affair," he told Europe 1 radio. "They took measures for the month of Ramadan but they never thought the attack would be on the beaches against tourists and the system of protection was set to start July 1."
Essebsi also said the country needed international help in securing its lengthy frontiers with Libya. The United States has already given millions in military equipment to help in this mission.
Some 80 mosques outside state control and known to propagate extremist messages are also set to be shut down. Interior Ministry official Walid Louguini told local radio the first of them were closed Tuesday, along with pro-jihadi social media sites.
Essebsi, 88, is a veteran of Tunisia's pre-revolutionary regime and was elected last fall on a platform of restoring security and dignity to the state.