The European Union and Afghanistan have agreed a deal that will ramp up the return of Afghan migrants who fail to gain asylum.