(Adds details)

TUNIS, Oct 2 (Reuters) - Tunisia has lifted a state of emergency imposed shortly after an Islamist militant attack in June this year on a beach resort, the presidency said on Friday.

President Beji Caid Essebsi declared the emergency shortly after 38 foreigners were killed in the attack in Sousse. In March, Islamist gunmen had killed 21 tourists at the Bardo Museum in Tunis. Islamic State claimed responsibility for both.

The North African country has undergone a largely peaceful transition to democracy since a 2011 popular uprising but the army has been fighting a rise in Islamist militant violence.

Tunisia is especially concerned about militants entering from neighbouring Libya, where Islamic State has established itself amid the chaos and security vacuum caused by two rival governments battling for control.

Tunisia started building a wall and trench along the 168 km (105 mile) border with Libya. The gunman in Sousse had been trained by militants in Libya before he carried out his attack.

(Reporting by Tarek Amara; Writing by Patrick Markey; Editing by Louise Ireland) ((pat.markey@thomsonreuters.com; +21620349006; Reuters Messaging: pat.markey.thomsonreuters.com@reuters.net))

Keywords: TUNISIA SECURITY/