Afghanistan leaders must settle the nation's disputed presidential election in the next two months if they want NATO troops to stick around past the end of the year, NATO Secretary General Anders Fogh Rasmussen told Fox News.

Rasmussen stressed that the race needs to be decided in time for his organization's September summit in Wales -- where a key security agreement must be signed -- and said he would like the new Afghan president to participate.  

"We do hope that the electoral process in Afghanistan can be concluded in due time before the summit so we can meet a new president at the summit and make decisions on our future engagement in Afghanistan including a training mission to train, advise, assist the Afghan security forces," Rasmussen told Fox News on Tuesday. 

But he said "time is now of the essence." 

In order for U.S. and NATO troops to remain in the country past the end of the year, the new Afghan president must sign a bilateral security agreement that gives forces authority to remain there as well as legal protections. The two candidates, Abdullah Abdullah and Ashraf Ghani, are mired in a runoff with each claiming victory despite the other refusing to bow out.

Both Abdullah and Ghani have said they would sign the security agreement that hangs in limbo with the election.

"We will be faced with major problems if we do not have a new president inaugurated by the time of our summit," Rasmussen said. "In that case we will probably not have signed the necessary security agreements and without security agreements, there will be no deployment of a training mission after 2014." 

Rasmussen was optimistic about the ability of Afghan forces that NATO troops have already trained. He doesn't expect a takeover by extremists as the Islamic State of Iraq and Syria (ISIS) is attempting in Iraq. The U.S. was unable to reach a security agreement with the Iraqi government and since troops pulled out in 2011, extremists -- many of whom have spilled over from the civil war in neighboring Syria -- have taken over parts of the country.

"I don't think we can compare Iraq and Afghanistan," said Rasmussen. "There are many differences including the fact that we have built a strong Afghan security force of about 350,000 Afghan soldiers and police and they have demonstrated a strong capability to handle security situations during recent months. So we are confident that they will be able to take full responsibility for security by the end of this year."

The other pressing challenge facing NATO is Russia's takeover of Crimea and its support of extremists operating inside Ukraine. Rasmussen said that Russia isn't taking the steps it needs to take and that deeper sanctions remain a possibility.     

"I do believe that if Russia were to intervene further in Ukraine or if Russia continues to destabilize the situation in eastern Ukraine, the international community will need to respond with broader and deeper economic sanctions and they would really hurt the Russian economy."

But Rasmussen said Russian President Vladimir Putin's actions in Ukraine underscore his greater goal: To dominate the region. For the pressure on Russia to subside, Rasmussen said NATO is sending a clear message that Putin has one course of action.

"Deescalate the situation, take immediate steps to withdraw troops from the Ukrainian border, seal the border, stop the flow of weapons and equipment, stop support for the separatists and engage in a constructive political process," he said.