This is a question that get's asked a lot. Not to discourage additional answers but here is a previous thread that dealt with this question, with some good answers as well as links to other threads: https://www.reddit.com/r/AskHistorians/comments/1myby5/what_were_the_reasons_for_the_soviet_invasion_of/
TL;DR: The government of Afghanistan asked the Soviets for help in dealing with an insurgency. The Afghani government was socialist and friendly to the USSR but not very popular inside the country. The Soviet goal was to prop up the Afghani government and keep it in power.