The 18-year-old had been under investigation for nearly two years, trading messages with a confidential informant, before agents sold him the rifle and ammunition and arrested him on the spot, they said.