WASHINGTON — A divided Supreme Court sided with gun control groups and the Obama administration Monday, ruling that the federal ban on “straw” purchases of guns can be enforced even if the ultimate buyer is legally allowed to own a gun.

The justices ruled 5-4 that the law applied to a Virginia man who bought a gun with the intention of transferring it to a relative in Pennsylvania who was not prohibited from owning firearms.

The ruling settles a split among appeals courts over federal gun laws intended to prevent sham buyers from obtaining guns for the sole purpose of giving them to another person. The laws were part of Congress’ effort to make sure firearms did not get into the hands of unlawful recipients.

Writing for the majority, Justice Elena Kagan said the federal government’s elaborate system of background checks and record-keeping requirements help law enforcement investigate crimes by tracing guns to their buyers. Those provisions would mean little, she said, if a would-be gun buyer could evade them by simply getting another person to buy the gun a fill out the paperwork.

In dissent, Justice Antonin Scalia said the language of the law does not support making it a crime for one lawful gun owner to buy a gun for another lawful gun owner.

In dissent, Justice Antonin Scalia said the language of the law does not support making it a crime for one lawful gun owner to buy a gun for another lawful gun owner.

The case began after Bruce James Abramski, Jr. bought a Glock 19 handgun in Collinsville, Virginia, in 2009 and later transferred it to his uncle in Easton, Pennsylvania. Abramski, a former police officer, had assured the Virginia dealer he was the “actual buyer” of the weapon even though he had already offered to buy the gun for his uncle using a police discount.

Abramski purchased the gun three days after his uncle had written him a check for $400 with “Glock 19 handgun” written in the memo line. During the transaction, he answered “yes” on a federal form asking “Are you the actual transferee buyer of the firearm(s) listed on this form? Warning: You are not the actual buyer if you are acquiring the firearm(s) on behalf of another person. If you are not the actual buyer, the dealer cannot transfer the firearm(s) to you.”

Police later arrested Abramski after they thought he was involved in a bank robbery in Rocky Mount, Virginia. No charges were ever filed on the bank robbery, but officials charged him with making false statements about the purchase of the gun.

A federal district judge rejected Abramski’s argument that he was not a straw purchaser because his uncle was eligible to buy firearms and the 4th U.S. Circuit Court of Appeals affirmed.

The Obama administration had argued that accepting Abramski’s defense would impair the ability of law enforcement officials to trace firearms involved in crimes and keep weapons away from people who are not eligible to buy them. The administration said that even if the purchase is made on behalf of someone eligible to buy a firearm, the purpose of the law is frustrated since Congress requires the gun dealers — not purchasers — to run federal background checks on people buying guns.

Abramski claimed Congress’ goal was to prevent guns from falling into the hands of convicted felons and others barred from owning firearms. He said that goal is not furthered if the gun is transferred to someone legally allowed to own guns.

The National Rifle Association sided with Abramski, asserting that the government wrongly interpreted the law and improperly expanded the scope of gun regulations. Twenty-six states also submitted a brief supporting Abramski’s view of the law, while nine states and Washington, D.C., filed papers bolstering the Obama administration.