The political challenges may be particularly daunting. The president says he wants to move the data out of the government’s hands. That has positioned him between two extremes. At one end is an odd mix of tea party Republicans and civil liberties Democrats who want the government to end its bulk collection of Americans’ records, not just shift where the data are stored. At the other end are powerful lawmakers, including the chairmen of the House and Senate intelligence committees, who have resisted any substantial changes.

Obama has tasked Attorney General Eric H. Holder Jr. and Director of National Intelligence James R. Clapper with devising a plan by March 28. But many in the administration have their eyes on a more significant date: In June 2015, the law that authorizes the bulk collection is set to expire, and officials say there is little prospect of renewing that authority amid the public backlash triggered by the exposure of U.S. surveillance programs by former intelligence contractor Edward Snowden.

“Congress’s deadline hangs over all of this,” said one administration official was not authorized to discuss the matter and spoke on the condition of anonymity.

The official was referring to the pending expiration of Section 215 of the USA Patriot Act, the law that underpins the program.

In some ways, the NSA controversy presents Obama with the inverse of the political problem he faced with the U.S. military prison at Guantanamo Bay, Cuba. He has spent six years trying to figure out how to shut down that facility. He may now have 18 months to find a way to preserve the NSA’s capabilities.