If the coughing/gagging/gasping ends with what sounds like a 'honking' noise, he may be suffering from kennel or canine cough. A contagious virus that thrives in dog-populated areas such as parks, kennels, groomers, and vet offices.
Or...he may have another respiratory condition with congestion or fluid built up in his lungs - as you and I would with bronchitis or pneumonia.
Last but not least, could he actually have something caught in his throat? Generally if there is an obstruction, dogs will not eat, drink, will vomit and/or appear to be in pain/discomfort with heavy or labored breathing.
IF he does have labored breathing, this is considered an emergency symptom and you need to get him to the vet as soon as possible. If he appears to be fine and behave normally in between these gagging episodes, then I would suspect an illness as suggested above. In this case, you would still need vet care at your earliest convenience for medication.
I wish you well and hope your dog recovers without incident!