(Adds comments from lawmaker, details on security)

TUNIS, Oct 8 (Reuters) - A lawmaker from Tunisia's ruling secular party escaped an assassination attempt on Thursday when a gunman riddled his car with automatic rifle fire from a passing vehicle.

There was no immediate claim of responsibility for the shooting but Tunisia is caught up in a growing battle against Islamist militants who have carried out two major attacks this year and in 2013 assassinated two opposition leaders.

"They attacked me from another car. He was just one gunman who fired eight bullets at me with a rifle as I was on my way into Sousse," said the lawmaker, Ridha Chareffedine, who represents the main secular Nidaa Tounes party.

Confirming the shooting, the interior ministry said authorities were closing off routes out of Sousse, a beach town where in June an Islamist gunman massacred 38 foreign tourists as they lay on the beach and around the hotel and pool.

"Our troops are out in force to stop this gunman and his vehicle," Interior Minister security chief Rafik Chelli said.

Last week authorities lifted a state of emergency imposed across Tunisia after the June attack in Sousse.

Hundreds of suspected Islamist militants have been arrested since the attack. But despite the crackdown, two men on a motorbike opened fire on policemen in Sousse in August, killing one and wounding two others.

The North African country has undergone a largely peaceful transition to democracy since a 2011 popular uprising, but the army faces a rising tide of Islamist militant violence and several thousand Tunisians have also joined up with militant groups fighting in Iraq and Syria.

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

(Reporting by Tarek Amara; writing by Patrick Markey; Editing by Gareth Jones) ((pat.markey@thomsonreuters.com; +21620349006; Reuters Messaging: pat.markey.thomsonreuters.com@reuters.net))