The White House cautiously urged Afghan President Hamid Karzai to sign a security agreement as soon as possible after he appeared to balk early Thursday, arguing that it is in the best interest of his country and U.S. national security.

“It's important for the Afghan government to get this approved and signed by the end of the year,” White House spokesman Josh Earnest told reporters Thursday. “The United States needs to coordinate [with its allies and the Afghans] on what our post-2014 presence would be like.”

Early Thursday Karzai surprised officials from both sides involved in finalizing the deal by saying that because of “mistrust” between him and Washington, any agreement would have to wait until his successor is elected before being signed.

“The agreement should be signed when the election is conducted, properly and with dignity,” he told the Loya Jirga, a council of Afghan elders Karzai convened to vote on approving the deal, according to a report in the Wall Street Journal.

“There is mistrust between me and America. I don't trust them, and they don't trust me,” he continued after he shared the contents of a letter President Obama sent him Thursday morning.

Afghan elections are slated for April but could be delayed for months as Karzai searches for a preferred successor.

The security agreement would set U.S. troop levels in Afghanistan after the 2014 drawdown of the U.S.-led NATO coalition. Currently there are 43,000 U.S. servicemen and women in Afghanistan, a figure that will decrease over the next year.

Earnest said President Obama has yet to decide the number of troops he would like to remain, if any, but he said any residual force would likely amount to “a few thousand.”

U.S. officials would like a security agreement by the end of the year, and argue that any delay would hamper plans to provide billions of dollars in much-needed funds and assistance to Afghan police and security forces, programs American and Afghan officials believe are critical to prevent the country from returning to Taliban control.

Karzai’s move comes just as both sides were reporting that they had finalized the language of the security agreement, ironing out contentious differences.

Despite the harsh words and surprising move from Karzai, Earnest tried to focus on the positive, saying that just a few months ago there were a doubts that both sides could agree on the basic parameters of a deal.

The U.S. and the Iraqi governments never did agree on a post-war security accord, forcing the Pentagon to pull out completely without leaving a force in place to help maintain security and train Iraq's police and military.

“The agreement that we're talking about was the product of a lot of work,” said Earnest. “I would remind you that there was a lot of skepticism, healthy skepticism on whether or not it was even feasible for the governments to reach an agreement along these lines.”

Expressing frustration with Karzai and Obama, Sen. John McCain, R-Ariz., said the Afghan leader's willingness to thumb his nose at the U.S. so flagrantly is a result of the president's mishandling of Middle East foreign policy.

“[Karzai] is very mercurial – he's very unpredictable and as he sees the United States leaving the region, he's not sure exactly what they're going to leave behind,” McCain told the Washington Examiner. “His first priority is to make sure he and his family remain in a position of influence in Afghanistan.”

McCain said Karzai's latest outburst “is another stumbling block” to the security agreement, but added that “it's very possible that we will overcome this one.”

More broadly, he argued, Karzai's comments are the direct result of Obama's failure to provide a cohesive Middle East policy.

“There's a perception of American weakness throughout the Middle East and it's there and it's real,” McCain said. “So people like Karzai, people like the Saudis, people like the Qataris, these people are now making accommodation for a diminution of U.S. influence in the region.”

“Karzai's latest is just another indication of that,” he continued. “They're looking at Iraq, they're looking at our failure in Syria, they're looking at Libya, they're looking at the whole Middle East. Can anyone tell what our policy is to Egypt? They certainly don't think there is one.”