Clustering and routing protocols play a pivotal role in reducing energy consumption and extending the lifespan of wireless sensor networks. However, optimizing energy efficiency to maximize network longevity remains a primary challenge for these protocols. This paper introduces QPSOFL, a clustering and routing protocol that integrates quantum particle swarm optimization and a fuzzy logic system to enhance energy efficiency and prolong network lifespan. QPSOFL employs an enhanced quantum particle swarm optimization algorithm to select optimal cluster heads, utilizing Sobol sequences for population diversification during initialization. Additionally, it incorporates Lévy flight and Gaussian perturbation-based position updates to prevent trapping in local optima. Benchmark experiments validate QPSOFL's efficacy compared to Harris Hawks Optimization (HHO), Grey Wolf Optimization (GWO), Particle Swarm Optimization (PSO), and Quantum Particle Swarm Optimization (QPSO), focusing on accuracy, search capability, and convergence speed. Within QPSOFL, a fuzzy logic system determines the best next-hop cluster head based on descriptors such as residual energy, energy deviation, and relay distance. Extensive simulations compare QPSOFL's performance in terms of network lifetime, throughput, energy consumption, and scalability against existing protocols E-FUCA, IHHO-F, F-GWO, and FLPSOC, demonstrating its superior performance over these counterparts.