Most NPCs serve a purpose. They can provide various services: some heal the player and their minions, repair the player's items, trade with the player or provide gambling services. In addition, most quests are obtained from NPC's. Some NPCs offer no services but an opportunity to talk to them, even having a special "Gossip" entry with a random speech.
Some NPC's merely have a decorative goal to simulate crowdedness; players usually can't interact with any of them. At best they can give out some random phrases, but are overall ambient objects.
There is no way to attack NPCs. However, some of them may attack the monsters, although usually the game script avoids that. Even if NPCs are allowed to fight, their damage is negligible, although they can sometimes draw the enemy's attention for a short time and buy the player a second or two. NPCs vital to the plotline are marked as "essential" and therefore may not be killed in battle.