You've guessed it, these words are all related.
I was thinking about jam making for some reason. If you have made jam you'll know it won't set properly with too little pectin. Thinking about jam reminded me of this and because I am always interested in word origins I went off and looked up pectin. Here's what I found in the OED.
Pectin was named pectique by its discoverer, H. Braconnot, who in 1825 formed the word from a Greek stem piktos (πηκτός), 'congealed', so you see the jam connection. We just borrowed pectic and pectin into English. But here's where it get interesting.
piktos is from a Proto-Indo-European root *pag-,'fasten' also seen in Latin pangere, 'fasten' or 'fix', the origin of pagina, 'page', as in a book; I think the notion is of a piece of writing made concrete.
Pangere is also the ancestor of pagan, which at first just meant a country dweller belonging to a settled community or particular district and only later developed the sense of 'not Christian'.
And so we come to peasant, which also means a country dweller. Latin pagus, 'country district', is also derived from the same PIE root, which evolved into Old French païs, 'country' and païsan, 'country dweller', which ultimately became English peasant.
Here's a truly dreadful Dad joke.
What jam would you make with old cars?
Traffic jam!
Tags: pangere, *pag-, PIE, pagan, peasant, page, pectin