The Afghan government on Wednesday banned YouTube to prevent people from watching an anti-Islam film that sparked a violent anti-American demonstration in Libya which killed the US ambassador.