They act on instinct, so they know, danger, hunger and reproduction, this I know for sure, some bigger ones like cichlids, have the cognitive ability to understand territories and recognise individual fish, Some of them mate for life, so they can tell their mate from the others, they also recognise their off spring and look after them for months.
Do I think they can experience pain? Maybe I would suspect bigger ones like cichlids as I mentioned, arowanas, discus etc it is possible they could experience some sort of pain, For example i have had some cichlids who had parasites and they kept trying to rub them off as if they were experiencing discomfort at the least.
Smaller ones like characids (Neon tetra etc) no definitely not, they are literally just running on instinct, as I have not observed the same awareness of parasites in them, they simply continue on as normal as if nothing is wrong, same if they are sick they will just keep going until they die.
If you wish to kill one and you worry about causing it pain, put it in clove oil first to put it to sleep then poison it with alcohol (Much like killing a human with nitrogen).
I keep many fish myself (Around 60 or so)