KABUL, Afghanistan — Amid highly public tensions with the United States over a long-term security deal, Afghanistan’s president looked to forge closer ties with neighboring Iran, agreeing in principle to start negotiating an economic and security “pact of friendship,” Afghan officials said.

During a one-day trip to meet with President Hassan Rouhani of Iran, President Hamid Karzai not only got a chance to reach out to a neighbor, but also to tweak the Western allies he has been at loggerheads with in recent weeks.

While Mr. Karzai and his staff have repeatedly said the intent is eventually to sign the bilateral security pact with the United States, allowing an American troop presence beyond the 2014 withdrawal deadline, Mr. Karzai has also added conditions before he signs it. Both American and Afghan officials see the chances of a completed deal by year’s end as basically dead, despite a recent vote by an assembly of Afghan leadership figures instructing Mr. Karzai to sign it.

Now, with the deadlock continuing, Mr. Karzai has publicly focused on bolstering regional ties. In addition to the Iran trip, he recently met with Prime Minister Nawaz Shari of Pakistan, and in coming days is to travel to India.