In Spain, irrigated agriculture is the most water-intensive sector, consuming around of 80% of water resources. Moreover, irrigation water distribution systems are the infrastructure by which one-third of water resource losses take place. Monitoring and controlling operations in irrigation canals are essential for mitigating leakages and water waste in operational actions. On the other hand, energy consumption by agriculture is around 5% of usage in developed countries and even higher in undeveloped countries. Although it is a small part of the total energy supply for a country, energy waste reduces the competitiveness of the agriculture sector, which continually reduces profit margins in an economic sector with very low profit margins already. The tool developed in this paper aims to increase the efficiency of water and energy management in the agricultural sector and is included in an overall control diagram for scheduled irrigation management. This tool, the optimal pumping flow (OPF algorithm), optimizes the pumping flow from the irrigation canal to the irrigation reservoir in terms of water level at the canal and reservoir, crop flow demand, system constraints, and energy prices. Regarding the results, the OPF algorithm can calculate the optimum pumping operations, being able to optimize water resource usage and energy expenses by ensuring that the water level at reservoirs remains within a specified range and that pump flow never exceeds a threshold. Further, it allows for the management of pump operations outside of peak hours. On the other hand, the OPF algorithm is also integrated into the overall control diagram in a second test. Here, the OPF algorithm collaborates with a control canal algorithm such as the GoRoSo algorithm to optimize canal gates and pump operations, respectively. In this scenario, OPF reduces cumulative energy expenses by 58% compared to the scenario where the pump station operates only when the reservoir water level is below a certain threshold.