For compatibility's sake, you may take a look at PIC16F873 or the PIC16F883. They have 28 pins by the way.
As for 20 pins, I would recommend PIC16F690. It's feature-packed and very cheap. The registers are not exactly the same, but if you successfully used PIC16F877, you should quite easily be able to use PIC16F690 by consulting the datasheet.
As per Tahmid, but you will find the 876/A has idential memory and registers to the 877/A, except its in 28 pins
The 873/A only has half the program memory, ram and eeprom.