Congress on Wednesday passed legislation that would effectively bar the transfer of Guantanamo detainees to the U.S. for trial, rejecting pleas from Obama administration officials who called the move unwise.

A defense authorization bill passed by the House and Senate included the language on the offshore prison, which President Barack Obama tried unsuccessfully to close in his first year in office.

The...