By Patrick Markey and Tarek Amara

SBIBA, Tunisia, May 17 (Reuters) - One of the young men was a high school literature student who helped his father tend the family olive trees in their isolated farming community near the Algerian border.

The other lived in the capital Tunis, had a taste for fashion and worked as a travel agent.

Jabeur Khachnaoui and Yassine el-Abidi came from stable, middle-class families and were well educated.

On March 18, they came together to attack Tunisia's Bardo Museum, shooting foreign tourists as they filed off buses outside the museum, and then taking more tourists hostage inside.

Over three hours they killed 22 people in all, including French, Italian, Japanese, Russian and Spanish visitors. Security forces eventually stormed the building and shot and killed the hostage-takers.

To their families, the two young men seemed to lead normal lives. But according to Tunisia's interior ministry, they both spent time in militant camps in Libya late last year before returning to Tunisia, their ideologies fine-tuned and basic military training completed.

Their stories show how difficult it will be for Tunisia to stop others making similar journeys. The country and region are full of young men like Khachnaoui and Abidi, and Islamist groups are increasingly targeting middle-class recruits.

The Bardo massacre has also reopened debate on the country's delicate balance between the need for security, and the rare freedoms enjoyed by both secular Tunisians and conservative Islamists.

Tunisia is one of the Arab world's most secular nations and has won praise for its democratic progress since the 2011 Arab Spring uprising, which began there. It has mostly escaped the violence and upheaval afflicting Libya and Egypt. And it has a new constitution, free elections and a political balance that have helped keep the country stable.

At the same time, Tunisia supplies the largest contingent of foreign fighters to extremist group Islamic State, according to the Tunisian government. Tunisians also take a leading role in jihadist ranks in neighbouring Libya, carrying out beheadings and running training camps. In all, more than 3,000 Tunisians now fight for militant groups in Iraq, Syria and Libya, according to Tunisian officials.

A senior Tunisian security source said the two young attackers were the product of profound political shifts in Tunisia since the Arab Spring allowed long-oppressed ultra-conservative Islamists to come into the open. "It was like a pressure cooker that was closed and burst open," he said. Young men go abroad for training or to fight, and return like ticking bombs. "The ones that come back, they can explode at any time."

Khachnaoui's father Ezzdine said he still cannot fathom why his son embraced such a violent ideology.

"I lost my son, but my son took their lives, and I don't know why," he said at the family's farmhouse in rural Kasserine province. "Was it extremist recruiters Was it the mosque All I know is I brought him up right."

Half a dozen other Tunisian families told Reuters similar stories. They all have had family members, including students, recent graduates and professionals, leave to fight abroad. Most of the families are middle class.

One family in the city of Sousse, a popular tourist resort, say they lost their son, a professional football player, to an Islamist group fighting in Syria. Another family - husband, wife, four children and two relatives - left the island resort of Djerba to travel through Turkey and live under Islamic State in Syria, local officials in Djerba say.

In Ouslatia, near the historic mosque town of Kairouen, more than 20 young men have left, residents say. One family there lost two brothers: One was killed fighting in Libya, the other became a commander in Islamic State in Syria, according to messages on social media. He was killed in March.

Many young Tunisians praise the country's democratic progress since the 2011 revolution, but also say a series of governments has failed to deliver promised economic opportunities. In recent weeks hundreds of unemployed youth, including university graduates, have begun hunger strikes and taken to the streets in southern towns to demand jobs. The growing sense of disappointment in the country, say experts on Islamic militancy, is fertile ground for extremist recruiters. <^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The middle-class Islamists behind Tunisia's museum attack (PDF) http://reut.rs/1IzE7zz Islamic State recruits as Tunisia grapples with freedoms ID:nL3N0Y55C7 How Denmark's unexpected killer slipped through the net (PDF) http://reut.rs/1GbELCJ

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>

SCHOOL YARD RECRUITERS

Jabeur Khachnaoui's family home sits on a plain of olive trees and fruit plantations near the town of Sbiba. The community of 6,000 people has long been known for its prized apples. The region's roads also sport signs of another source of income: stalls that hawk contraband gasoline and fuel, smuggled across the nearby border with Algeria, Tunisia's wealthy oil-producing neighbour.

Isolated and with few opportunities for its young, Sbiba seems just the place to breed discontent. It was in a similar town some 80 km (50 miles) to the south in late 2010 that an impoverished street vendor set himself alight in protest after police confiscated his wares, triggering protests that spread and erupted into the Arab Spring.

Khachnaoui, 21, was not uneducated, unemployed or poor. His family is relatively well off, with a large house and land. Khachnaoui's uncles are teachers; his sister studied literature at university.

Khachnaoui's relatives all say nothing obvious changed in the young man who was raised to be moderate in his religious beliefs. He travelled 18 km to his school by bus every day. He helped on the farm and spent his free time collecting apples.

Only his mild upset over images of Iraq and Syria or of immodestly clad women in television commercials offered a clue to his shifting ideas, his father, Ezzdine, said. Jabeur would turn off the television or leave the room.

But if his life at home appeared normal, things had changed at school in recent years, officials and fellow students say.

The local mosque was already under the control of a hard-line imam, Sbiba's mayor Abd Elatif Kechini said. By early 2013, Salafists had set up a tent on wasteland outside the Sbiba school and began to proselytise.

It was a time of flux in Tunisia. Before the revolution that ousted President Zine el-Abidine Ben Ali in 2011, Tunisia's religious conservatives mostly kept out of politics. Islamist groups were banned and Islamists regularly arrested.

But in the vaccuum that followed, fierce argument erupted over the role of Islam in politics. New political groups flourished. Some, such as the country's licensed Salafi party, Hezb Ettahrir, renounced violence. Others such as Ansar al-Sharia, which had links to al-Qaeda, were more militant and attacked art shows, theatres and even Sufi Muslim shrines.

In May 2013, Tunisia's then Islamist-led government banned Ansar al-Sharia, forcing its leadership and members underground. Security forces began a low-level war against Islamist militants.

But conservative imams continued to control some mosques and attract followers. That was the case with the Salafists in the tent outside Khachnaoui's school.

"They were always trying to get us to talk about prayers, the headscarf and jihad," said Amine, a student at a kiosk near the dusty wasteland outside the school.

Kechini, the mayor, who is also one of the school's teachers, said Khachnaoui slowly drifted into the hands of the extremists. Before 2014 he had been an average student focusing on science. He switched to literature. In the middle of last year he grew more radical, Kechini said. He led prayer sessions at school, and even aggressively demanded to hold them during class times. At times he would wear the traditional long robes favoured by Salafists.

Kechini recalls a class debate over Islam and politics just before Khachnaoui disappeared to Libya. The young man moved to the back of the class when the teacher tried to engage him and sat smirking, refusing to join in the discussion.

Tunisian authorities put him on a watch list of young men associating with hard-liners, but did not see him as a particular threat, a security source said.

Khachnaoui left home without notice last December. He called the family from a Libyan mobile number saying that he was going to Iraq. In February, during his last call home, he said he would not return, his father said. "We tried to persuade him, we tried to bring him back, but he just said everything was fine and he was staying."

More than 20 residents of Sbiba, including students and professionals, have left to fight for militant groups outside Tunisia, said Kechini. Authorities in Sbiba have now banned the Salafist tents from near the school, while the imam at the mosque, who could not be reached for comment, has been pressured into changing his rhetoric, the mayor said.

"There is really nothing here, but the cafe or the mosque," he said. "This town was always marginalised, but now it's a black mark as we will always be associated with terrorism."

BREAKFAST, WORK, ATTACK

Khachnaoui's fellow attacker Yassine el-Abidi also came from a middle-class family. Relatives say the 27-year-old was a bon-vivant interested in fashion. He enjoyed dancing at weddings and had no qualms about occasionally drinking alcohol, they said. He showed no dramatic change in his ideology and never criticised others for behaving in ways strict Salafists would frown upon.

Beginning in 2014, though, he started to spend more time at the Tawba mosque, which serves his Tunis neighbourhood and which was taken over by Salafists following the 2011 revolution. Residents say ultra-conservative imams gave sermons at night there and Salafists sometimes clashed with police who wanted to take back control of the mosque.

In December 2014, Abidi left home, his uncle said, telling his family he was on a two-month business trip on Tunisia's coast. Authorities say they believe he travelled to Libya where he received training in basic weapon skills at a jihadist camp.

When Abidi returned home, he continued to work at the travel agency. Nothing appeared out of the ordinary, even on the day of the attack. He had shared a breakfast of dates and olive oil with his family, and later asked for a break at work.

It was then that he joined Khachnaoui and attacked the Bardo.

"He was always well dressed and always joking around," said his uncle Mohammed. "I told his family, you are victims of terrorism too."

(Edited by Simon Robinson) ((patrick.markey@thomsonreuters.com; Reuters Messaging: patrick.markey.thomsonreuters.com@reuters.net))

Keywords: TUNISIA ATTACK/GUNMEN (SPECIAL REPORT, PIX, GRAPHI