The deal also gives landlocked Afghanistan access to Pakistani ports to boost its trade with other nations.
Correspondents say the deal marks a real effort to ease tensions between the two neighbours.
The accord was signed during the visit to the region by US Secretary of State Hillary Clinton.
In an interview with the BBC's Kim Ghattas in the Pakistani capital Islamabad, Mrs Clinton spoke of the need to bring the two countries closer together.
She also said said Washington wanted Pakistan to do more to tackle Islamist militants.
The deal between Afghanistan and Pakistan was signed by the trade ministers at a ceremony in Islamabad. Afghan Finance Minister Omar Zakhilwal, who played a key role in the difficult talks, described the agreement as "historic".