Aptamers are short single-stranded DNA or RNA oligonucleotides and can be selected from synthetic combinatorial libraries in vitro. They have a high binding affinity and specificity for their targets. Agarose gels, nitrocellulose membranes, and adsorptive microplates are often used as carriers to immobilize targets in the SELEX (systematic evolution of ligands by exponential enrichment) process, but the subsequent separation step is tedious and time-consuming. Therefore, we used magnetic nanoparticles (MNPs) as carriers to immobilize the target, hepatitis B surface antigen (HBsAg), which is convenient for fast magnetic separation. In this study, we first selected DNA aptamers against HBsAg by immobilizing HBsAg on the surface of carboxylated MNPs. The ssDNA library of each selection round was prepared by asymmetric PCR amplification for the next selection round. To obtain aptamer sequences, the final selected products were purified by gel electrophoresis, then cloned, and sequenced. DNA aptamers that specifically bind to HBsAg were successfully obtained after 13 selection rounds. The selected aptamers were used to construct a chemiluminescence aptasensor based on magnetic separation and immunoassay to detect HBsAg from pure protein or actual serum samples. There was a linear relationship between HBsAg concentration and chemiluminescent intensity in the range of 1-200 ng/mL. The aptasensor worked well even in the presence of interfering substances and was highly specific in the detection of HBsAg in serum samples, with a detection limit 0.1 ng/mL lower than the 0.5 ng/mL limit of an ELISA in use at the hospital. This aptasensor can contribute to better detection of hepatitis B virus infection.