Thousands of years ago man discovered that he could grow food instead of hunting and gathering all the time. It began in the ancient Near East and Southwest Asia about 10,000 years ago. It's roots goes back to climate change in the Epipaleolithic period about 10,000 years earlier. Along with growing food came the raising of domesticated animals and the preservation of crops. Some historians believe that grown of crops began as an accident when wandering people discarded remains of plant foods in piles in cleared areas, then they returned to the sites to find the same types of plants they had eaten were growing. Finally, they connected the leaving of seed one season to find edible plants the next. Farming began when people began to save and planted seeds of their favorite plants. So, to answer your question it was all an accident.