This is one of those questions that is purely speculative in its answer as none of us were there at the time to observe the process. That being said, I will take a stab at an answer.
Humans had waste pits or dung heaps where their excrement and food scraps were thrown out of the dwelling. Any raw seed would have had the opportunity to sprout and grow at the edges of the dunghill. This would have made it easier for people to get food. Depending on the type of seed, it may have been barley, wheat, or even a type of legume. The people would have seen this and perhaps had an "ah ha!" moment of discovery. Perhaps they should save some of each type of seed they gathered and plant it. They may have discovered "farming" through observations to their gods and goddesses by burying part of their harvest in the earth as a gift back to the gods, they "invented" farming. At any rate, around 3000 BCE to 1000 BCE , we see evidence of farming practices in several places near rivers all over the ancient world.
What we do know is that at some point people began growing crops in an organized manner in a part of the world known as the Fertile Crescent, the Indus Valley, and the Huang River in China. These had a consistent source of water and favorable climate conditions for the practice of farming crops. The silt from the rivers provided excellent fertile soil in which to begin the practice of farming. The earliest crops were wheat, barley, rice, peas and lentils.
Necessity, they say, is the mother of all inventions. This maxim applies to development of farming also. As population of human beings and the average number of people in a community living together increased beyond a limit, the land area within their reach was not sufficiently big to sustain their life by hunting and gathering alone. Thus humans were forced to develop other means of obtaining. This is the primary reason for hunter-gatherers becoming farmers.
Of course to start farming activities, people had to first learn the technique of farming. This could have happened accidentally, as people noticed plants growing at places where food was discarded by them.