YouTube said it would ban videos relating to the sale or assembly of guns and certain gun accessories, as tech giants face growing pressure to limit the promotion of firearms.

The world’s largest video site, a division of Alphabet Inc.’s Google, said this week it would prohibit all videos that link directly to sites that sell guns or accessories known as bump stocks, which allow certain firearms to fire as rapidly as machine guns. Bloomberg News and the website Tubefilter reported the policy shift, which YouTube posted on...