A search for long-lived particles (LLPs) using 140 fb^{-1} of pp collision data with sqrt[s]=13 TeV recorded by the ATLAS experiment at the LHC is presented. The search targets LLPs with masses between 5 and 55 GeV that decay hadronically in the ATLAS inner detector. Benchmark models with LLP pair production from exotic decays of the Higgs boson and models featuring long-lived axionlike particles (ALPs) are considered. No significant excess above the expected background is observed. Upper limits are placed on the branching ratio of the Higgs boson to pairs of LLPs, the cross section for ALPs produced in association with a vector boson, and, for the first time, on the branching ratio of the top quark to an ALP and a u/c quark.