A man on the F.B.I.’s Ten Most Wanted list was shot and killed by an agent during a predawn raid at a hotel in North Carolina on Wednesday, ending an 18-month search that spanned four states on opposite ends of the country.

The suspect, Greg A. Carlson, 47, was wanted in connection with an armed burglary and attempted sexual assault in Los Angeles in July 2017. The agency said in an announcement publicizing his placement on the most wanted list last year that “he should be considered armed and extremely dangerous.”

John A. Strong, the special agent in charge of the F.B.I. field office in Charlotte, N.C., said Mr. Carlson was found after a local police officer spotted a suspicious vehicle early Wednesday in the parking lot of the WoodSpring Suites in Apex, N.C., a few miles west of Raleigh.

The officer ran the car’s license plates and determined it to be the car associated with Mr. Carlson and listed on his F.B.I. wanted poster. The officer alerted the F.B.I., which sent an agent to the hotel and determined that Mr. Carlson was in a room there.