The core idea of massive multiple-input multiple-output (MIMO) systems is to raise the throughput and spectral efficiency (SE) of the cell system by placing a huge number of antennas at the base station (BS) to serve multiple users. Since the use of pilots is mandatory for channel estimation, this article discusses the problem of pilot contamination (PC) that affects the SE of the massive MIMO system. Due to the short coherence time in communication systems, the length of the corresponding pilot sequence is limited, and the number of orthogonal pilots that can be assigned to each cell is limited, which will inevitably lead to the repeated use of the pilot sequence in nearby cells which leads to appearance the PC problem. The PC in the networks could be eliminated through the proper scheduling of the pilot sequences and will be achieved by the proper pilot scheduling algorithm. Accordingly, this paper proposes a scheduling algorithm named eagle-crow optimization, which eliminates the contamination and promotes the SE of the massive MIMO system, under different practical constraints and requirements such as the number of antennas and users. The proposed algorithm is a combination of two optimization algorithms that are the crow search (CSA) and bald eagle search (BES) algorithms. Many studies have been performed using crow search (CSA) and bald eagle search (BES) algorithms. However, most of them did not consider PC problems in MIMO systems. The motivation behind the use of these two techniques is that the proposed eagle-crow optimization inherits the hunting characteristics of the eagle and the memory features of the crow in order to prevent the repetition of pilot assignments. The achievements of the proposed scheduling are assessed based on the performance of SE, when the number of antennas in the BS increases to 1000, the SE of the proposed method is 44.91 bps/Hz, and the percentage improvement of the proposed method is high when compared to the existing methods, Random pilot allocation, WGC-PD, and SPRS+WGC-PD.