The troops retreated over the border to "save their own lives", according to a statement by Tajikistan's border guard.
Violence has risen in Afghanistan and the Taliban have been making significant gains, particularly in the north of the country, in recent weeks.
The surge comes as the US, UK and allies withdraw after 20 years.
The vast majority of remaining foreign forces in Afghanistan have left ahead of a September deadline. There are concerns that the Afghan military, who were supposed to take over security in the country, will collapse.