Image copyright Getty Images Image caption Dogs have been going on walkies for a very long time

Dogs were part of a key moment in human history - when our ancestors began trying their hand at farming.

As the first farmers moved out of the Middle East, herding animals such as sheep and goats, dogs tagged along too, say scientists.

The DNA evidence fills in some of the gaps in the story of how wolves became the dogs of all shapes and sizes that we know today.

Farming began in what is known as the Fertile Crescent of the Middle East.

This includes parts of modern-day Iraq, Syria, Lebanon, Jordan, Israel and Egypt.

Humans who were living as hunter-gatherers settled down and started growing wild varieties of crops like wheat, barley, peas and lentils.

They also domesticated animals from wild sheep, cows and pigs. About 9,000 years ago, they moved into Europe and Asia, taking their animals and farming know-how with them.

Image copyright Getty Images Image caption A border collie and Czechoslovakian wolf dog in communication

The new study shows their dogs also went on the trip.

The evidence comes from DNA extracted from canine remains found at archaeological sites across Europe and Asia.

"Our study shows that dogs and humans have an intertwined story - dogs followed humans during this migration across Europe," said Dr Morgane Ollivier of the University of Rennes in France.

"We show in this paper that dogs and humans were already really connected."

Image copyright Getty Images Image caption Wolves in Norwegian winter forest

The journey from wolves to dogs

The story of how dogs came to be tamed from wolves is a complex one

Dogs evolved from wolves about 20,000 to 40,000 years ago when they were tamed by human hunter-gatherers

They may have been tamed from two different populations of wolves living thousands of miles apart

The long process of domestication began to alter the behaviour and genes of wolves and they eventually evolved into the dogs that we know today.

When the dogs arrived in Europe, they mixed with the dogs that were already there, changing the gene pool.

Centuries of dog breeding have mixed up the genes of dogs further. Modern dogs, of all shapes and sizes, are very different now to those early farm dogs who accompanied their owners on their travels.

The research is published in the journal Biology Letters .

Follow Helen on Twitter .