A Muslim American mayor of a New Jersey town said he was illegally detained at the John F. Kennedy International Airport in New York City by border patrol agents who questioned him about 'meeting with terrorists'.

Mohamed Khairullah, the mayor of Prospect Park, New Jersey, explained in a video shared on his YouTube page that he was held at the airport after returning from a vacation in Turkey with his wife, 10-year-old son, nine-year-old and two-year-old daughters, and 14-month-old son.

'Customs and Border Patrol agents took away my phone after holding me and my family for almost three hours,' Khairullah said.

Khairullah, who has been the mayor of Prospect Park since 2005, said the experience was 'frustrating' and 'terrifying'.

Mohamed Khairullah (left), the mayor of Prospect Park, New Jersey, said he was illegally detained at the John F. Kennedy International Airport in New York City by border patrol agents who questioned him about 'meeting with terrorists' after his family vacation to Turkey

According to Khairullah, agents initially asked him standard questions about where he traveled from and who he visited.

But the questioning then took a different turn after Khairullah told the agents he and his family had just flown in from Turkey.

Khairullah explained to Ahmed Mohamed, the litigation director of the New York chapter of the Council on American-Islamic Relations (CAIR), that the agents asked him: 'Do you know about any terrorist groups forming over there [Turkey] or did you meet any terrorists?'

The mayor said it was in that moment that he felt 'insulted', especially after serving his community for more than 18 years and prior to that as a volunteer firefighter.

'I felt that I was selected because of my name and identity,' Khairullah said.

After telling the agents that he didn't meet with or know of any terrorists groups in Turkey, Khairullah said he requested to end the interview and stopped answering their questions.

'Because I stopped answering questions. Because I told him "enough is enough, I don't want to be harassed" he said, "well now we have to inspect your phone",' Khairullah told Mohamed.

According to Mohamed, who called the incident 'a clear case of profiling', CBP 'violated their own rules' when they asked for the mayor's phone.

Khairullah explained that he was held at the airport after returning from a vacation in Turkey with his wife, 10-year-old son (left), nine-year-old daughter (right), two-year-old daughter (second from right), and 14-month-old son (second from left)

A spokesperson for the CBP in New York (file image of JFK Airport) said the agency was 'not at liberty to discuss an individual’s processing due to the Privacy Act'

However, Khairullah, who didn't know that the agents were 'violating his rights' at the time, consented and handed over his mobile phone.

A short time later, Khairullah asked for his phone to be returned to which an agent told him that if he was revoking his consent, then they would have to confiscate the the device.

Khairullah said the agents held his phone for 12 days until CAIR was about to get them to return it.

A spokesperson for the CBP in New York told CNN that the agency was 'not at liberty to discuss an individual’s processing due to the Privacy Act'.

According to the spokesperson, CBP’s 'authority to engage in border searches is articulated in numerous statutes and has been repeatedly affirmed by the Supreme Court of the United States'.

'For a minuscule number of travelers, this inspection may include electronic devices such as computers, disks, drives, tapes, mobile phones and other communication devices, cameras, music and other media players and any other electronic or digital devices,' the spokesperson added.

Mayor Khairullah said he has not ruled out legal action against the CBP.