The opposition legislator had just left parliament when he was attacked by gunmen on a motorcycle, police say.