Two men from Kazakhstan and a man from Cambridge were arrested and charged today in the Boston Marathon bombings investigation, federal prosecutors said.

Azamat Tazhayakov and Dias Kadyrbayev, both 19 and of New Bedford, were charged with conspiracy to obstruct justice by plotting to dispose of a laptop computer and a backpack containing fireworks belonging to bombing suspect Dzhokhar Tsarnaev, the US attorney’s office said in a statement.

At a brief initial appearance this afternoon in US District Court in Boston, Tazhayakov and Kadyrbayev waived their right to a bail hearing. They will appear in court again May 14. In a separate appearance, Phillipos also waived his right to a bail hearing. Another hearing was slated in his case for Monday.

Phillipos’s defense attorney, Derege Demissie, said after the hearing that Phillipos had nothing to do with the actions of Tazhayakov and Kadyrbayev and was simply charged with making a “misrepresentation” to authorities.

Tazhayakov “feels horrible and was shocked to hear that someone he knew” was involved with the bombings, said his defense attorney, Harlan Protass. “He looks forward to the truth coming out in this case.”

Kadyrbayev “absolutely denies the charges,” said his defense attorney, Robert G. Stahl.

Tazhayakov, Kadyrbayev, and Phillipos all began attending UMass Dartmouth together at the same time in 2011. They were all friends with Tsarnaev, authorities said.

The trio told investigators that Kadyrbaev removed Tsarnaev’s backpack, which contained fireworks that had been opened and emptied of gunpowder, from Tsarnaev’s dorm room on the evening of April 18, shortly after the FBI released photos of the two bombing suspects (which the FBI later identified as Dzhokhar Tsarnaev and his brother, Tamerlan), according to an affidavit by Special Agent Scott Cieplik attached to the complaint.

Kadyrbayev and Tazhayakov both admitted they agreed to throw away the backpack after concluding from news reports that Dzhokhar Tsarnaev must be one of the bombers. Kadyrbayev decided to remove the backpack from Tsarnaev’s room “to help his friend Tsarnaev avoid trouble,” the affidavit said.

Kadyrbayev allegedly later threw the backpack in a dumpster at the New Bedford apartment complex where Kadyrbayev and Tazhayakov lived.

The backpack was taken away by a garbage truck, but was recovered last week inside a black garbage bag by the FBI at a New Bedford landfill, the affidavit said.

The affidavit also alleged that Phillipos changed his story, saying at first that he had never gone to Tsarnaev’s dorm room but in a fourth interview admitting that he had joined the two others and gone to the room and taken the backpack. He said he had discussed with the two others what to do with the backpack but had fallen asleep and, upon awakening, discovered the backpack was gone.

The backpack, when it was found, contained the fireworks, a jar of vaseline, a UMass Darmouth homework assignment sheet from one of Tsarnaev’s classes, and other items, the affidavit said.

Kadyrbayev told investigators he decided to take Tsarnaev’s laptop as well because he did not want Tsarnaev’s roommate, who was there when the trio stopped by, to think Kadyrbayev was stealing or behaving suspiciously by just taking the backpack, the affidavit said. It wasn’t immediately clear from the affidavit what happened to the laptop computer.

The FBI searched Tsarnaev’s dorm room several days later. It has disclosed in court documents that agents found BBs, a large pyrotechnic, and a black jacket and white hat matching those worn by the bombing suspect in surveillance footage who was later identified as Tsarnaev.

Kadyrbayev first met Tsarnaev after starting college in fall 2011 and became closer friends with him in the spring 2012, often socializing with him and even meeting with Tsarnaev’s family at Tsarnaev’s home. Tazhayakov also became friends with Tsarnaev at UMass Dartmouth in fall 2011, the affidavit said. The affidavit also said Phillipos was friends with Tsarnaev.

Tsarnaev is facing federal charges of using a weapon of mass destruction and malicious destruction of property resulting in death in the twin bombings that struck near the Marathon finish line on April 15. His brother, Tamerlan, 26, was killed in a confrontation with police in Watertown several days afterward as the two tried to flee the area. Police say they were trying to subdue Tamerlan Tsarnaev after a shootout when Dzhokhar Tsarnaev ran him over in a desperate escape.

Authorities say the Tsarnaevs also killed an MIT police officer as they tried to escape the area. No charges have been filed yet in that case.

The White House and law enforcement authorities have previously suggested that the Tsarnaevs may have acted alone without clear ties to foreign governments or terrorist groups.

But investigators have continued to eye other people who knew the brothers to see if they provided them with any help before or after the attacks.

Lawyers for the men said at the hearing the men had cooperated with Homeland Security and FBI investigators for hours and were only college buddies with Dzhohkar Tsarnaev and should be released.

The men were being detained in the Suffolk County jail and appeared before Judge Steven F. Day via videoconference, wearing prison scrubs, from the jail. The consul of Kazakhstan, relatives of one of the men, as well as US government officials were in the court.

The hearing marked the men’s first court appearance since immigration officials arrested and jailed them 11 days ago in New Bedford.

The hearing raised questions about why the men were allowed to stay in the United States if their visas were allegedly invalid.

Kadyrbayev, who had studied engineering, was dismissed from UMass after the fall semester, but stayed in the United States. His lawyers argued that he should be allowed to leave the United States voluntarily. A hearing on Kadyrbayev’s case will be held on May 22.

Tazhayakov, an economics major, had his visa terminated on Jan. 4, but he was allowed to reenter the country on Jan. 20 in New York, the judge said in court. The discrepancy puzzled Judge Day. “That doesn’t make any sense,” he said. Day set a bail hearing for Tazhayakov for May 9.

A UMass Dartmouth official said both Robel Phillipos and Kadyrbayev left the university after the fall semester. Phillipos withdrew for reasons that were unclear today, while Kadyrbayev was expelled for poor grades.

Tazhayakov was enrolled until this week, but university officials suspended him today when the criminal charges were filed. “The normal procedure when a person is accused of a crime is to suspend him pending the outcome of that case,” said John Hoey, assistant chancellor for public affairs.

The Tsarnaev brothers once lived in Kyrgyzstan, which neighbors Kazakhstan. People in both countries speak Russian because they all lived in the former Soviet Union, where the official language was Russian.

The UMass Dartmouth campus, still reeling after learning that Dzhokhar Tsarnaev was a sophomore here, had more bad news to absorb today.

“It’s kind of hard to digest that students who came here to study could do such a thing,” said Raja Nageswaran, 25, an MBA grad student.

He said the two Kazakhs had been to the off-campus housing he shared with other international students a few times for parties. He remembered they played pool with his roommates. One came more frequently than the other, but he was not sure which one. On one occasion, Tsarnaev also attended.

The last time the Kazakhs were at a party was in October, before Halloween, he said. Nothing much stood out, although the Kazakhs liked to drive their black BMW hard, making it squeal, he said. He knew them only through mutual friends.

The school has several hundred international students, he said, who tend to bond because they are internationals. “They were definitely fun-loving. That stood out. They loved to party,” he said.