The doubly charmed tetraquark recently discovered by the LHCb Coll. is studied by using (2+1)-flavor lattice QCD simulations with nearly physical pion mass MeV. The interaction between and in the isoscalar and -wave channel extracted from the hadronic spacetime correlation by the HAL QCD method is attractive and leads to a near-threshold virtual state with a pole position keV. The virtual state is shown to evolve into a loosely bound state as decreases to its physical value by using a potential modified to MeV based on the pion-exchange interaction. Such a potential is also able to describe the LHCb data on the mass spectrum.