Seifeddine Rezgui, the Tunisian man who killed 38 people at the beach resort of Sousse, is thought to have been trained in Libya, security sources say.
A senior official at the Tunisian interior ministry told the Associated Press that Rezgui had been in Libya in January, the same time as two men who attacked a Tunisian museum in March.
Most of the dead in Sousse were foreign tourists, including 30 Britons.
The Islamic State group (IS) has claimed the attack as its own.
“The attacker trained in Libya with weapons at the same period as the Bardo [museum] attackers,” Rafik Chelli from the interior ministry told AP.
IS also said it was behind the Bardo museum attack in Tunis that left 22 people dead.
Mr Chelli said that Rezgui had travelled to the Libyan town of Sabratha at the same time as the Bardo attackers.
“He crossed the borders secretly,” Mr Chielli told AP.
IS has a significant presence in Libya, Tunisia’s eastern neighbour, and is thought to control the major towns of Derna and Sirte.
The Tunisian authorities have released photos of two suspects, Bin Abdallah and Rafkhe Talari – friends of Rezgui that the police have yet to locate.
Rezgui, 23, was radicalised while studying engineering.
The Tunisian authorities have already arrested several suspected accomplices.
However, Tunisian President Beji Caid Essebsi has admitted that the security services were not prepared for an attack of this kind.
He said extra security had been put in place at other locations during the Islamic holy month of Ramadan, but nobody had expected beaches to be a target.
The UK Foreign Office has updated its travel advice to warn that further terrorist attacks in Tunisia are possible, and has urged people to be vigilant.
Tour companies have laid on extra flights and about 10,000 British tourists have flown home from Tunisia since Friday, according to the Association of British Travel Agents.
The repatriation of bodies of Britons killed in the attack will begin on Wednesday, Downing Street has said.
Twenty-one Britons have been identified as victims, with nine more believed to be among the dead, it added.
Three Irish tourists, two Germans, a Belgian and a Portuguese national died in the attack.
The repatriation process is expected to take several days and will be followed by a joint inquest into the deaths of all the British victims.
The RAF flew the last four of the seriously injured back to the UK on Tuesday and they are now in hospital undergoing treatment.
In other developments:
- a major exercise to test how British security services would respond to a terrorist attack has taken place in London
- a national minute’s silence will take place in the UK on Friday at 12:00 BST, a week after the shooting
- flags on government and royal buildings will fly at half-mast
- every primary and secondary school in England is to receive guidance on how to spot grooming of pupils by extremists
Tunisia beach attack: The victims
The names of those killed in the attack are slowly emerging. Here’s what we know so far about those who lost their lives, as well as those who are injured and missing.
Some survivors have also been speaking out about their ordeal.