Protesters threw bottles and police opened fire with foam bullets as tensions boiled over in Barcelona.