The men were arrested in the Qarghayi district of northeastern Laghman province on Sunday, just 50m from where Khalilzad had planned to inaugurate a road along with Afghanistan's interior minister, chief presidential spokesman Jawed Ludin said on Monday.
Two senior Afghan officials said the men had confessed to their crimes and said they were in Afghanistan to fight jihad.
"Their aim was to assassinate Khalilzad, and they came to Afghanistan specifically for this operation," said one of the officials, both of whom spoke on condition of anonymity due to the extreme sensitivity of the intelligence and their positions within the government.
Afghan television later broadcast a video of the suspects in custody.
The men, all young and with thin moustaches, are seen sitting on a brown sofa being questioned by a man off camera. They identified themselves as Murat Khan, Noor Alam and Zahid, and say they are from Pakistan. None confessed on camera or were asked any questions about the attack.
The US embassy in Kabul had no immediate comment on the assassination plot, but said it would release a statement later.
Attacks are expected to escalate
ahead of the elections
Khalilzad, who is to be the next American ambassador to Iraq, cancelled his appearance at the road opening at the last minute and was never in danger, the Afghan official said.
Interior Minister Ali Ahmad Jalali also cancelled his appearance.
The official said the fact the plotters knew of Khalilzad's trip, and that Jalali was supposed to be with him, was very disturbing.
"We don't know how they got this information," he said.
The men were arrested by the National Security Directorate, Afghanistan's version of the CIA, after a tip-off that an assassination plot was being planned.
Agents lying in wait surrounded the men's station wagon when it slowed to go over a speed bump. They found the weapons -three Kalashnikov assault rifles and a rocket-propelled grenade launcher with two shells - hidden among clothes.
The men told agents they had been trained at a hideout in Wah Cantonment, 35km west of Islamabad and home to a major Pakistani weapons and munitions factory. They were later moved to Bara, a town in the North West Frontier province, and crossed into Afghanistan last week.
Days before the attack was due to take place, they called accomplices in Pakistan and asked that they send vests packed with explosives, but were told they would not arrive in time and were instructed to carry out the assassination with the weapons they had.
The officials said the men were all young. Two said they came from the northwestern Pakistani town of Peshawar, and the other said he was from Mansehra, about 150km to the northeast.
It was not clear who had sent the men. One of the officials said the Afghan government was extremely angry at what he called a lack of cooperation from Islamabad in stopping militants from crossing the border.
He said Pakistan's lack of resolve was a factor in both the assassination plot and a recent upsurge in violence across southern Afghanistan that has left hundreds dead.
Afghanistan says Pakistan is not
doing enough to fight violence
"We have always believed that if we got cooperation from Pakistan, this violence wouldn't be happening," he said.
"These militants are getting support from people in Pakistan, and we are not convinced when Islamabad says it can't control them."
Pakistani Information Minister Shaikh Rashid Ahmed reacted angrily to any hint of an official sanction.
"This is a baseless allegation," he said. "Pakistan is not involved in any such thing now or in the past."
"Pakistan is not involved in any such thing now or in the past"
Shaikh Rashid Ahmed,
Pakistan information minister
Afghan officials often accuse Pakistan of not doing enough to seal its border, and say privately they believe some elements of the army and intelligence network are helping Taliban and al-Qaida fighters. Pakistan denies the charges. Officials boast they have stationed tens of thousands of troops along the border and arrested more than 700 al-Qaida suspects.
Pakistan was a supporter of the Taliban militia before it switched sides and allied with the United States after the 11 September 2001 attacks. A US-led coalition ousted the Taliban from power in late 2001 for harbouring al-Qaida, the network of Osama bin Laden.
Afghan Defence Minister Rahim Wardak warned on Friday that al-Qaida had slipped at least half a dozen agents into the country, and was seeking to bring Iraq-style carnage to Afghanistan.
Two of the men - both Arabs - detonated themselves earlier this month in attacks that killed 20 people and wounded four US troops.
Al-Qaida members are believed
to have entered the country
On Monday, US military spokesman Colonel James Yonts warned that foreign militants backed by networks channelling them money and arms had come into Afghanistan to subvert legislative elections in September. He said that for operational security reasons he could not identify the networks or who was backing them.
The Afghanistan-born Khalilzad has been a powerful force in the country, often portrayed as the ultimate power behind US-backed President Karzai. The two men are close, having known each other for decades.
Khalilzad had warned last week that terrorist and rebel attacks were likely to escalate ahead of the elections.