NEW YORK — When Ahmad Khan Rahami returned in March 2014 from a nearly yearlong trip to Pakistan, he was flagged by customs officials, who pulled him out for a secondary screening. Still concerned about his travel, they notified the National Targeting Center, a federal agency that assesses potential threats, two law enforcement officials said.

It was one of thousands of such notifications every year, and a report on Rahami was passed along to the FBI and other intelligence agencies, according to the law enforcement officials.

Five months later, when Rahami's father told the police that he was concerned about his son having terrorist sympathies, federal agents again examined his travel history. And again, despite Rahami's now having been flagged twice for scrutiny, the concerns were not found to warrant a deeper inquiry. Ahmad Rahami was not interviewed by federal agents.

But now, the travel history of Rahami, who is accused of carrying out bombings in New York and New Jersey last weekend, has become a focus of investigators, a subject made all the more urgent by details contained in a notebook that suggests he drew inspiration largely from the Islamic State.

In particular, Rahami repeatedly cites a founding member of the Islamic State who called on Muslims around the world to take up whatever arms they could find and spill the blood of nonbelievers.

In an undated handout image provided by authorities, a portion of the notebook allegedly kept by Ahmad Khan Rahami. Writings in the bloody and tattered document suggest that Rahami drew inspiration from both al-Qaida and from the Islamic State group. (Handout via the New York Times)
In an undated handout image provided by authorities, a portion of the notebook allegedly kept by Ahmad Khan Rahami. Writings in the bloody and tattered document suggest that Rahami drew inspiration from both al-Qaida and from the Islamic State group. (Handout via the New York Times)

The assessment of Rahami by the FBI began in August 2014, and they once again reviewed the report by the National Targeting Center.

The center was created after the Sept. 11, 2001, attacks to function as an intelligence analysis agency within the Department of Homeland Security.

"By identifying high-risk passengers and cargo well before they would cross our land borders, sail into our ports or touch down on our tarmacs, the NTC team is on duty to protect our people and economy 24/7," the federal government's description of the agency says.

It is unclear how much information the report contained about Rahami's activities during the 11 months he was in Pakistan, starting in April 2013, and about any other trips he made while abroad.

Investigators are interested in learning more both about a three-week trip he made to Afghanistan and another trip he may have made to Ankara, Turkey, according to law enforcement officials. The report by the NTC did not mention any travel to Turkey, according to a law enforcement official who reviewed it.

According to records provided by the New York Police Department to customs officials, Rahami traveled for an unspecified length of time in January 2014, according to a law enforcement official and records obtained by The New York Times.

That trip came at a time when international authorities were concerned about the flow of foreign combatants to Syria to fight in the civil war there, but before the Islamic State became widely known as a source of international terrorism.

The Islamic State was just making its first expansion into Iraq then, taking the city of Fallujah. Mostly, the group was seen as an Islamist rebel force in the Syrian conflict that had become focused on grabbing territory from fellow opposition groups — especially the Nusra front, which like, the Islamic State, had started as a branch of al-Qaida but instead became an enemy.

In an undated handout photo provided by Union County Prosecutor’s Office, Ahmad Khan Rahami. Rahami is in custody after being suspected of being responsible for bombings on Sept. 17, 2016, in both New York and New Jersey. (Union County Prosecutor’s Office via The New York Times)
In an undated handout photo provided by Union County Prosecutor’s Office, Ahmad Khan Rahami. Rahami is in custody after being suspected of being responsible for bombings on Sept. 17, 2016, in both New York and New Jersey. (Union County Prosecutor’s Office via The New York Times)

The questions about where Rahami drew his inspiration and whether he had help are at the center of the investigation even as an intense legal battle takes shape over how his case is being handled.

Defense lawyers are fighting to get Rahami before a judge so he can be appointed a lawyer and have charges laid out against him, while prosecutors are pushing back.

The new information being gleaned from Rahami's notebook, a copy of which was provided to The Times by a law enforcement official who was not authorized to speak to the press, paints a substantially different picture from what could be understood by the snippets highlighted in the criminal complaint filed in federal court on Tuesday night.

That summary mentioned Anwar al-Awlaki, once al-Qaida's leading propagandist, who is equally popular with ISIS followers but made no mention of the Islamic State leader.

The pages of Rahami's journal echo the talking points of the ISIS spokesman and senior strategist Abu Muhammad al-Adnani, who in May advised followers around the world to commit violence in their home countries if travel to Syria proved too difficult.

Fragments of the journal — much of it rendered illegible because of blood stains — suggest that Rahami may have himself been frustrated in his attempts to reach Syria and was using that as justification for committing terror at home.

One page has the word "blocked," followed by: "You should have let us meet death overseas."

On a subsequent page, he wrote "back to Sham," an archaic regional name that has come to be used for Syria. He goes on: "I looked for guidance and Alhumdulilah," he says, using an Arabic expression praising God. "Guidance come / Sheikh Anwar / Brother Adnani / Dawla. Said it clearly attack The Kuffar in their backyard." The last sentence appears to reference al-Adnani's speech this summer in which he beseeched followers to hurt unbelievers in whatever manner they could and wherever they found them.

Rahami makes clear that he planned to die a martyr: In "my heart, I pray to the beautiful wise Allah / to not take jihad away," he said. "I begged for shahada," he continued, using the Arabic for martyrdom, "and inshallah this call will be answered."

Rahami also refers to more recent comments al-Adnani made.

"If the tyrants have closed in your faces the door to Hijrah, then open in their face the door of jihad and make their act a source of pain to them," al-Adnani said a speech released by the Islamic State in May. "The smallest action you do in the heart of their land is dearer to us than the largest action by us, and more effective and more damaging to them."

Mohammad Rahami, father of the suspected bomber Ahmad Khan Rahami, in Elizabeth, N.J., Sept. 21, 2016. More details have emerged about Ahmad Rahami and his activities on the day of the attacks in New York and New Jersey, including information from a notebook suggesting he was inspired by both Al Qaeda and the Islamic State group. (Dave Sanders/The New York Times)
Mohammad Rahami, father of the suspected bomber Ahmad Khan Rahami, in Elizabeth, N.J., Sept. 21, 2016. More details have emerged about Ahmad Rahami and his activities on the day of the attacks in New York and New Jersey, including information from a notebook suggesting he was inspired by both Al Qaeda and the Islamic State group. (Dave Sanders/The New York Times)

The authorities are also still searching for two men who apparently stumbled on one of the bombs planted in Manhattan on Saturday evening and took the explosive device out of a bag before walking away with the bag — although officials said they were not believed to be part of the plot.

On Wednesday, investigators, who believe the bag may be a valuable piece of evidence, released images of the men — one wearing a pink golf shirt and the other wearing a light brown button-down collared shirt. The images were taken from surveillance video that shows the men walking on 27th Street between Avenue of the Americas and Seventh Avenue in Chelsea between 8 and 9 p.m. on Saturday.

The authorities said they did not believe the men were tied to Rahami.

"We have no reason to believe they're connected," Chief James Waters, head of the New York Police Department's Counterterrorism Bureau, said at a news conference on Wednesday morning.

The city police commissioner, James P. O'Neill, said they were considered witnesses.

Rahami is recovering in Newark from wounds he suffered in a shootout with the police in Linden, New Jersey, on Monday morning, when he was taken into custody.

The U.S. attorney general, Loretta E. Lynch, said Wednesday that the government would bring Rahami to New York City to face charges.

"In the near future, it is our intention to bring the defendant to the Federal District Court for the Southern District of New York," she said in remarks made in Washington.

The chief federal public defender in Manhattan, David E. Patton, wrote on late Tuesday night to Magistrate Judge Gabriel W. Gorenstein, asking for a court hearing at the earliest possible time and proposing that if Rahami's health did not permit his travel to Manhattan, Patton's lawyers could represent him in New Jersey at the hearing by telephone or video.

"The Sixth Amendment requires that he be given access to counsel on the federal charges, and that he be presented without delay," Patton wrote.

The U.S. attorney for the Southern District of New York, Preet Bharara, asked the judge to deny the request. In court papers on Wednesday, his office said that because Rahami was arrested by the local police and is being held on state charges in connection with the shootout, he is not in federal custody. That, the prosecutors argued, means that he does not yet have a right to a prompt appearance in federal court and the provision of a lawyer there.

The judge, in a ruling issued Wednesday night, found that the court did not have the authority to appoint him a lawyer or order an appearance at this time.

Peter Liguori, the deputy public defender in Union County, where the shooting of the Linden police officers took place, said he had not received notification that Rahami had requested a lawyer. "We want to make sure that his constitutional rights are protected," Liguori said. "If he or his family has requested our assistance, we will certainly help him and make sure that he gets proper representation."