WASHINGTON — He lived out of his van in the Northern Virginia suburbs and took showers at the Y.M.C.A. On Facebook, he posted furious criticism of President Trump and pledged allegiance to Senator Bernie Sanders of Vermont. Back home in Illinois, neighbors complained to the police of his practicing his shooting near their home.

Shortly after 7 a.m. on Wednesday, the police say, James T. Hodgkinson, 66, of Belleville, Ill., opened fire on a baseball field in Alexandria, Va., just steps from the Y.M.C.A., spraying bullets at members of the Republican congressional team practicing there.

Four people were shot in the assault, including Representative Steve Scalise of Louisiana, the majority whip and third-ranking Republican in the House. An ensuing firefight with the police took Mr. Hodgkinson’s life.