Molecular beacons (MBs) are DNA-based probes that detect DNA or RNA fragments and hold promise for monitoring diseases and studying protein-nucleic acid interactions. MBs usually use fluorescent molecules as fluorophores for reporting the target detection event. However, the fluorescence of the traditional fluorescent molecules can bleach and even be interfered with the background autofluorescence, reducing the detection performance. Hence, we propose to develop a nanoparticle-based MB (NPMB) that uses upconversion nanoparticles (UCNPs) as a fluorophore, which can be excited by near-infrared light to avoid background autofluorescence and thus enables us to detect small RNA from complicated clinical samples such as plasma. Specifically, we employ a DNA hairpin structure, with one segment complementary to the target RNA, to position a quencher (gold nanoparticles, Au NPs) and the UCNP fluorophore in close proximity, leading to the quenching of the fluorescence of UCNPs in the absence of a target nucleic acid. Only when the hairpin structure is complementary with the detection target, will the hairpin structure be destroyed to separate Au NPs and UCNPs, resulting in the instant recovery of the fluorescence signal of UCNPs and the consequent ultrasensitive detection of the target concentrations. The NPMB has an ultra-low background signal because UCNPs can be excited with NIR light with a wavelength longer than the emitted visible light. We demonstrate that the NPMB can successfully detect a small (22-nt) RNA (using a microRNA cancer biomarker, miR-21, as an example) and a small single-stranded DNA (complementing the cDNA of miR-21) in aqueous solutions from 1 aM to 1 pM, with the linear detection range being 10 aM to 1 pM for the former and 1 aM to 100 fM for the latter. We further show that the NPMB can be used to detect unpurified small RNA (miR-21) in clinical samples such as plasma with the same detection region. Our work suggests that the NPMB is a promising label-free and purification-free method for detecting small nucleic acid biomarkers in clinical samples with a detection limit as low as the aM level.