Yam means - Not to do
Niyam means - To do regularly
Eg. of Yama
1) Ahimsa - Non violence
2) Titiksha - Not to repel back ie to tolerate heat and cold without resisting
3) Asteya - Not to steal
4) Akrodh - Not to speak rude or get angry
Eg. of Niyam
1) To do Puja or Paath regularly
2) Punctuality is also one example of Niyam but it is mostly excluded from religious behaviours
3) To do fasts on particular days every month
4) To visit places of pilgrimage as tour at least once every year.
As per scriptures, Creator made the world but the power or Deity who looks after them is Lord Vishnu. He and His allies who rules this universe and are the oldest powers give prime importance to Niyams and followers of Niyam.
Sincere adherence to Niyams gives divine protection. And slips or forgetting to follow Niyams creates flaws in divine protection. Such flaws gives opportunity to evil powers or opposing powers or punishing powers an upper hand to degrade our position. Such is a belief.
Just as tongue remains protected in between teeths that way Niyams can protect a religious being. Such beliefs in Brahmins like Chanakya is believed to be the root cause of their rise.
In old age person suffers lot of physical pains. As per one belief , root cause of this is not following Yams.