One of Obama's first actions as president was to order the closure of the prison facility in Cuba, set up 13 years ago under president George W. Bush, but he has been thwarted by domestic and international obstacles.
Obama said he signed the defense policy bill, known as HR 3979, because it provides "vital benefits for military personnel and their families, as well as critical contingency authorities needed to counter the Islamic State" group and other emerging threats.
But he criticized the law for including provisions that bar the United States from building or modifying any prison facilities to house the Guantanamo inmates.
"As I have said many times, the continued operation of this detention facility weakens our national security by draining resources, damaging our relationships with key allies and partners and emboldening violent extremists. Closing the detention facility is a national imperative," Obama said in a statement.
"Instead of removing unwarranted and burdensome restrictions that curtail the executive branch's options for managing the detainee population, this bill continues them."
Six years after Obama was elected having made a campaign promise to close the prison, 136 detainees still remain, 67 of whom have been cleared for release by either the Bush or Obama administrations.
"The Guantanamo detention facility's continued operation undermines our national security. We must close it," Obama said.
"I call on members from both sides of the aisle to work with us to bring this chapter of American history to a close."
The Guantanamo Bay prison -- built to house terror suspects after the September 11, 2001 attacks -- has long been controversial, both for the incarceration of uncharged and untried suspects and for the brutal interrogations of some detainees.
Obama also suggested he could use his powers to speed up the transfer of some prisoners, even without Congress's approval.
"The executive branch must have the flexibility, with regard to those detainees who remain, to determine when and where to prosecute them," he said.
In the event that the restrictions on the transfer of detainees operate in a manner that violates constitutional separation of powers principles, my administration will implement them in a manner that avoids the constitutional conflict."
US defense chief Chuck Hagel also criticized the new act, saying it prevented the Defense Department from pursuing many cost-saving measures.
"The longer we defer tough choices, the more difficult they will become down the road," Hagel said in a statement.