BOSTON (AP)  A knife-wielding man killed by the terror investigators who had him under surveillance was confronted because he had bought knives and talked of an imminent attack on “boys in blue,” the FBI said Wednesday.

Usaama Rahim plotted for at least a week to attack police, the FBI said in a complaint against a family member who was arrested Tuesday, the day Rahim was shot to death. On Wednesday, the relative, David Wright, was ordered held on a charge of conspiracy with intent to obstruct a federal investigation.

The FBI said Rahim, who had previously discussed beheadings, bought three fighting knives and a sharpener on or before May 26 and he told Wright on Tuesday he would begin trying to randomly kill police officers.

An anti-terror task force of FBI agents and Boston police, faced with an imminent threat, confronted Rahim on a sidewalk and fatally shot him when he refused to drop his knife, authorities said.

An affidavit written by an FBI agent assigned to Boston’s Joint Terrorism Task Force refers to a recorded conversation between Rahim and Wright in which Wright made a comparison to “thinking with your head on your chest.” The FBI said that was a reference to Islamic State propaganda videos showing severed heads on the chests of beheading victims.

The FBI affidavit said Rahim initially told Wright about a plan to behead someone outside Massachusetts. On Sunday, Rahim, Wright and an unidentified man met on a beach in Rhode Island to “discuss their plans,” the FBI affidavit said.

“Wright indicated that he agreed with Rahim’s plan and supported it,” the affidavit states.

Authorities searched a home in Warwick, Rhode Island, on Tuesday and Wednesday but wouldn’t confirm the search was related to the investigation. They also wouldn’t confirm how Rahim, 26, and Wright, 24, are related.

Early Tuesday morning, Rahim called Wright and told him he had changed his plans and no longer planned to kill someone in another state, the affidavit says. Instead, he said he was going to “go after” the “boys in blue,” it says, an apparent reference to police officers.

During the recorded conversation, Rahim told Wright, “Yeah, I’m going to be on vacation right here in Massachusetts. … I’m just going to, ah, go after them, those boys in blue. Cause, ah, it’s the easiest target and, ah, the most common is the easiest for me,” the affidavit says.

The FBI said the phrase “going on vacation” refers to committing violent jihad.

Authorities allege that during that conversation, Wright advised Rahim to destroy his smartphone, wipe his laptop computer and prepare his will.

On Wednesday, authorities moved swiftly to manage perceptions of the shooting, which killed a black man whose family is well known among Muslims and African-Americans in Boston.

Rahim’s mother is a nurse at Boston University. His older brother, Ibrahim Rahim, is a scholar known for preaching after the Boston marathon bombings that violence is anti-Islamic.

Ibrahim Rahim initially posted a message on Facebook alleging police repeatedly shot his brother in the back while he was on a cellphone calling their father for help. But his version unraveled Wednesday after police showed their video of the confrontation to community leaders.

Darnell Williams, president of the Urban League of Eastern Massachusetts, said he could “150 percent corroborate” the police account. The images clearly show that Usaama Rahim “was not on a cellphone and was not shot in the back,” Williams said.

Police Commissioner William Evans said officers confronted Rahim because “military and law enforcement lives were at threat.”

The video, which police did not make available publicly, shows that Rahim menaced the officers with a large military-style knife and they initially backed away before shooting him when he refused to drop it, police said.

Williams said he’s not ready to call the shooting justifiable, and a Boston Muslim leader, Imam Abdullah Faaruuq, said it was unclear from the “inconclusive” video whether police had to use deadly force.

“They might have approached him in a different way,” Faaruuq said.

Ibrahim Rahim could not be reached for comment Wednesday as he traveled to Boston to bury his brother.

Usaama Rahim was under investigation after spreading Islamic State propaganda online and communicating with other people about it, said U.S. Rep. Michael McCaul, who chairs the House Homeland Security Committee.

“These cases are a reminder of the dangers posed by individuals radicalized through social media,” the Texas Republican said.

Prosecutor Stephanie Siegmann said Wright posed a serious risk of fleeing or obstructing justice if not held pending a June 19 hearing. Wright’s attorney, Jessica Hedges, denied that, saying he has deep roots in the Boston area and an “incredibly loving and supportive family.”

Hedges urged the government to be “as transparent as possible” and “abide by the law” as it investigates this case, saying “we have serious concerns about that already.”

Authorities quickly showed the video to black and Muslim community leaders. The meeting “was all about pulling the community together,” Evans said.

After the Boston Marathon bombings in 2013, Ibrahim Rahim described Jihadis who promote terror as “hell-bent on Islam’s destruction from within,” and he urged fellow Islamic leaders to drive “a mass recall of the rhetoric of hate and to suppress any and all human desire to harm others based on any contrived justification.”

Yusufi Vali, executive director of the Islamic Society of Boston Cultural Center, where Usaama Rahim briefly worked as a guard, said Ibrahim Rahim “is a great guy and preaches a very moderate form of Islam.” Vali said Usaama Rahim did not regularly pray at the center and did not volunteer there or serve in any leadership positions.

Boston voter registration records describe Rahim as a student. Other records show he applied for a security guard license in Florida in 2011 but didn’t follow through. A spokeswoman said Rahim had worked for CVS since March.

Rahim’s shooting is being investigated by the Suffolk district attorney’s office and the FBI, routine for shootings involving police. The Council of American-Islamic Relations said it’s monitoring them. The Black Community Information Center, an activist group in Boston, called for the U.S. Department of Justice to lead a more independent review.

___

Associated Press writers Collin Binkley and Phil Marcelo contributed to this report from Boston, and Eric Tucker contributed from Washington.

___

This story has been corrected to show the FBI alleges only Rahim, not Wright, bought three knives.