WASHINGTON — In a series of secret nighttime flights in the last two months, the Obama administration made more progress toward the president’s goal of emptying the military prison at Guantánamo Bay, Cuba, than it had since 2009. The accelerated pace came after an era of political infighting and long bureaucratic delays.

Now 127 prisoners remain at Guantánamo, down from 680 in 2003, and the Pentagon is ready to release two more groups of prisoners in the next two weeks; officials will not provide a specific number. President Obama’s goal in the last two years of his presidency is to deplete the Guantánamo prison to the point where it houses 60 to 80 people and keeping it open no longer makes economic sense.

Although Mr. Obama still has a long way to go, senior administration officials say the president is expecting Ashton B. Carter, his nominee for defense secretary, to move more aggressively on emptying Guantánamo than did Chuck Hagel, the previous defense chief. Mr. Obama may be commander in chief, but Mr. Hagel had the power to delay approval of prisoner transfers from Guantánamo for months. Fearful that the freed detainees could become a security threat to American troops abroad, Mr. Hagel moved slowly, frustrating the White House, and ultimately resigned under pressure.

Mr. Carter’s views on Guantánamo are not widely known, but his colleagues say he is attuned to Washington politics and Mr. Obama’s desire to be part of the last chapter of the Guantánamo prison, which the United States opened in 2002 to house people suspected of being connected to terrorist groups. “If the president doesn’t succeed in making substantial steps to closing Gitmo now, it will have a very severe impact on his legacy,” said J. Wells Dixon, senior staff attorney with the Center for Constitutional Rights, which has represented Guantánamo prisoners.