The Australian government said Monday it would detain a doctor accused of supporting the foiled car bomb attacks in London and Glasgow on immigration violations, overriding a magistrate's order granting him bail.

Mohamed Haneef's work visa was canceled because the Indian doctor had "failed the character test," and he would be taken into immigration custody if he meets his bail conditions, Immigration Minister Kevin Andrews said.

"I reasonably suspect that he has, or has had, an association with persons engaged in criminal activity, namely terrorism, in the U.K.," Andrews told reporters in Canberra, the national capital. "That's the basis on which I have made this decision."

Hours earlier, Queensland state Magistrate Jacqui Payne granted Haneef bail, saying there was no clear evidence he was involved in the car bomb plot.

Police, acting on information from British investigators in the attack plot, arrested Haneef on July 2 as he tried to board a flight from the eastern city of Brisbane to India.

Haneef, 27, was charged Saturday with providing support to a terrorist organization by giving his mobile phone SIM card to British suspects Sabeel and Kafeel Ahmed when he moved to Australia in July 2006.

Haneef is a distant cousin of the Ahmed brothers and he shared a house with them in Liverpool before moving to Australia for a job at a hospital on Queensland state's Gold Coast.

Haneef's lawyer Stephen Keim has slammed the government's case as "extremely weak," saying his client only left the SIM card so his cousin could take advantage of a special deal on his mobile phone plan.

Under Australian law, the government can withdraw a person's visa for a variety of reasons, including if the minister judges a person is not of good character.

Magistrate Jacqui Payne set the bail for Haneef with several conditions, including staying away from international ports, checking in with police three times a week and putting up an $8,700 bond.

Andrews said that if Haneef meets the bail conditions, immigration officials would step in before he can be freed and bring him to a detention facility in Sydney.

The move was criticized by Cameron Murphy, the secretary of the Australian Council for Civil Liberties.

"The reason we have an independent court system is so these incredibly important decisions are made for the right reasons, and aren't subject to political interference," Murphy said. "It is not appropriate for the government to just keep him incarcerated because they don't like the decision of the magistrates court."

Haneef's wife has maintained her husband is innocent and pleaded with authorities to help free him, Indian media reported Sunday.

"I had patience till now because I thought they would not charge him without reason," said Firdaus Arshiya, according to the Sunday edition of the Hindustan Times. "The charges are baseless and senseless."

In Britain, police charged Sabeel Ahmed, 26, with withholding information that could prevent an act of terrorism. He was arrested in Liverpool the day of the Glasgow attack and is due to appear in a London court on Monday.

Kafeel Ahmed, is believed to have set himself ablaze after crashing an explosives-laden Jeep into the Glasgow airport on June 30 and is hospitalized with severe burns.

Police also released two men arrested at a Scottish hospital after the failed attacks. Police said no charges would be filed against the men, a 24-year-old and a 27-year-old arrested at the Royal Alexandra Hospital in Paisley.

With their release, three of the eight people detained in the case have been freed and three have been charged since a pair of cars packed with gas cylinders and nails were found in central London on June 29. The next day, two men crashed a flaming Jeep Cherokee, loaded with gas canisters and gasoline, into security barriers at Glasgow airport's main terminal.

On Saturday, a British judge gave police until July 21 to continue questioning a Jordanian doctor, Mohammed Asha, 26, who was detained on a northern England highway on June 30. He was detained with his wife, who was released Thursday without charge.