Pathogen detection has become a major research area all over the world for water quality surveillance and microbial risk assessment. Therefore, designing simple and sensitive detection kits plays a key role in envisaging and evaluating the risk of disease outbreaks and providing quality healthcare settings. Herein, we have designed a facile and low-cost colorimetric sensing strategy for the selective and sensitive determination of β-galactosidase producing pathogens. The hexagonal boron nitride quantum dots (h-BN QDs) were established as a nanozyme that showed prominent peroxidase-like activity, which catalyzes 3,3',5,5'-tetramethylbenzidine (TMB) oxidation by H2O2. The h-BN QDs were embedded on a layer-by-layer assembled agarose biopolymer. The β-galactosidase enzyme partially degrades β-1,4 glycosidic bonds of agarose polymer, resulting in accessibility of h-BN QDs on the solid surface. This assay can be conveniently conducted and analyzed by monitoring the blue color formation due to TMB oxidation within 30 min. The nanocomposite was stable for more than 90 days and was showing TMB oxidation after incubating it with Escherichia coli (E. coli). The limit of detection was calculated to be 1.8 × 106 and 1.5 × 106 CFU/mL for E. coli and Klebsiella pneumonia (K. pneumonia), respectively. Furthermore, this novel sensing approach is an attractive platform that was successfully applied to detect E. coli in spiked water samples and other food products with good accuracy, indicating its practical applicability for the detection of pathogens in real samples.