A man was arrested Thursday and charged with making a bomb that he planned to use to attack an abortion clinic, a device that went off in the home of a friend while authorities were trying to disable it.

Robert F. Weiler Jr., 25, of Forestville, was arrested more than 140 miles away at a Garrett County rest stop on Interstate 68 around 12:30 a.m. after he called agents from the Bureau of Alcohol, Tobacco, Firearms and Explosives to surrender. He told authorities that he made the bomb and had a gun he planned to use in the attack, according to court documents.

The device, a pipe bomb filled with nails which was stored in a closet at the friend's home in Riverdale, exploded several hours later as a bomb technician tried to defuse it. No one was injured, but the house was set on fire.

Weiler was charged in U.S. District Court on four counts that included making a destructive device and possessing an illegal handgun. He was being held Thursday afternoon at the Garrett County Detention Center.

Phone messages left at Weiler's home were not returned.

According to an ATF affidavit, Weiler planned to use the weapons to attack an abortion clinic in Greenbelt. He told authorities that he would use a .40-caliber handgun he stole from a friend to "shoot doctors who provided abortions" the affidavit states.

A woman who answered the phone at the clinic said they had not heard of the threat.

Weiler had earlier stolen money from his parents and told friends that he had a gun and bomb for his attack, according to the affidavit. On Wednesday night, some of those friends revealed his plans to the ATF and Prince George's County police.

After Weiler called the ATF later that night, Maryland state troopers arrested him without incident. In his car was the handgun and a magazine with ammunition.

While being questioned by troopers and the ATF, Weiler said he had built a pipe bomb and placed it in the closet of the Riverdale house. The device was made of a pipe, black powder, nails and seven feet of fuse.

The bomb exploded as fire officials tried to disable it around 3:30 a.m. Thursday, and set fire to the top floor of the home. Damage was set at $20,000.

Police also discovered Weiler was convicted in 2003 in Utah for obstructing police, according to the affidavit. It is unclear what his punishment was for that conviction.

Weiler was charged Thursday with possessing an illegal explosive device, making an illegal explosive device, illegally possessing a firearm with a prior felony conviction and possessing a stolen firearm. He is expected to appear in federal court Friday.