A gas pipeline system is in an almost continual state of transition due to changing gas demand. A control method is required to keep a gas pipeline operating in an energy-saving status and provide reliable transmission service for the customers. Model predictive control (MPC) predicts the future states of a system, making it suitable for following gas demand changes. However, to avoid computation time challenges associated with formulating the MPC problem as a large-scale MINLP, an online two-level MPC system is proposed, comprising an upper-level economic MPC (EMPC) and a lower-level tracking MPC (TMPC). EMPC adopts energy cost as the objective function and utilizes a simplified nonlinear model to address long-horizon optimization, while TMPC tracks the status optimized in EMPC, to find the optimal output pressure and the on-off status of the compressors and compressor stations. The performance of the method is demonstrated through application to case studies.