THORNTON, Colo. — Scott Allen Ostrem lived alone in a one-bedroom apartment where his neighbors say he cursed at them, and he was often seen carrying a rifle to and from his home. Over the years, he accumulated a trail of minor criminal charges, debts and defunct businesses.

And on Wednesday night, the police said, Mr. Ostrem, 47, “nonchalantly” walked into a Walmart in this city of about 136,000 north of Denver and fatally shot two men and a woman, then calmly turned around and drove off in a red Mitsubishi subcompact.

He was arrested Thursday morning after an all-night manhunt when he was spotted driving by his Denver apartment, about seven miles south of the Walmart.