A real-time digital time-stamp sorting algorithm used in the In-Beam positron emission tomography (InBeam PET) is presented. The algorithm is operated in the field programmable gate array (FPGA) and asmall amount of registers, MUX and memory cells are used. It is developed for sorting the data ofannihilation event from front-end circuits, so as to identify the coincidence events efficiently in a largeamount of data. In the In-Beam PET, each annihilation event is detected by the detector array anddigitized by the analog to digital converter (ADC) in Data Acquisition Unit (DAQU), with a resolution of 14bits and sampling rate of 50 MS/s. Test and preliminary operation have been implemented, it can performa sorting operation under the event count rate up to 1 MHz per channel, and support four channels intotal, count rate up to 4 MHz. The performance of this algorithm has been verified by pulse generator and 22Na radiation source, which can sort the events with chaotic order into chronological order completely. The application of this algorithm provides not only an efficient solution for selection of coincidenceevents, but also a design of electronic circuit with a small-scale structure