TUNIS, Tunisia — Tunisia's president declared a state of emergency on Saturday in response to a second deadly attack on foreigners in three months, saying the country is "not safe" and risks collapse from further extremist attacks. With a nationwide televised address, President Beji Caid Essebsi officially reintroduced urgent security measures for Tunisia that had been lifted in March 2014. Essebsi said an "exceptional situation required exceptional measures" but pledged to respect freedom of expression. The decision came just over a week after a gunman at the popular beach resort of Sousse attacked foreign tourists, killing 38 people. Essebsi said the state of emergency would last 30 days. "Tunisia faces a very serious danger and it should take any possible measures to maintain security and safety," he said. "As we see in other countries, if attacks like Sousse happen again, the country will collapse." Essebsi blamed the poor security in Libya for Tunisia's problems, and the lack of international resolve in targeting Daesh (so-called IS) throughout the region. He said Tunisia specifically had been a target of the extremist group because it had a functioning, secular democracy. The gunman behind the beach attack was killed by police and Daesh later claimed responsibility for the massacre, a blow to Tunisia's tourism industry. Thirty of the 38 dead in the attack were British tourists. In March, gunmen killed 22 people, again mostly tourists, at The National Bardo Museum outside Tunis. Tunisia's government has promised new laws to increase police powers and provide for harsher penalties for terrorism convictions. Immediately after the beach attack, the prime minister pledged to post armed guards at tourist sites and close mosques outside government control. The Sousse governor and security chiefs were fired as was a top official in the gunman's hometown, according to the prime minister's office. Tunisia was under a state of emergency from January 2011, at the outbreak of the Arab Spring, until March 2014. It initially included a curfew and a ban on meetings of more than three people. Although those measures were relaxed, police and the military retained powers to intervene in unrest or for security reasons. — AP