At least five people have died and 40 injured after a knife man mowed down pedestrians then stabbed a policeman before being shot by armed officers.