A hierarchically porous carbon microsphere (PCM) with phosphorus doping (A-PCM) for an oxidase-like sensor and supercapacitor was prepared by the hydrothermal reaction using d-(+)-xylose as a carbon source, F127 as a pore expanding agent, and phosphoric acid as an activation agent. Phosphoric acid activation resulted in phosphorus doping that was beneficial to produce micropores. The introduction of F127 promoted the formation of large mesopores and macropores. In contrast with conventional PCMs, the prepared A-PCM demonstrated a large specific surface area of 1469.71 m2/g, distinctive adsorption and diffusion properties, best conductivity, and cycling stability, which enabled it to serve as a high-performance electrode material that displayed a high peak current response with about 130-fold enhancement compared with bare GCE, intrinsic oxidase-like characteristics, excellent electrocatalytic capacity for niclosamide in linear ranges from 0.3 to 100 μM with a low detection limit of 8.4 nM under the optimum operation conditions, and a high specific capacitance of 445.71 F/g at a current density of 1 A/g.