I would imagine he has eaten something which doesn’t agree with him.
Don’t give him anything to eat for 24 hours, let the gut settle, then after the starvation period just give him three small meals of either boiled chicken or fish with rice for a day then do the same the following day and on the third day start introducing his normal food gradually.
Keep off the treats for a while. Too many of these can give him diarrhoea.
If he is still the same after the starvation period I should take him to see the Vet. It doesn’t sound like a virus but if it continues he may need a course of antibiotics.