Updated:

The command

VersionCommand
Java 1.21.11+/gamerule minecraft:mob_griefing false
Java 1.21.10 and earlier/gamerule mobGriefing false
Bedrock/gamerule mobgriefing false

Set it back to true to undo. It applies to the whole world and every player in it.

What it stops

What it also switches off

The rule covers mobs touching blocks and items in general, so useful behavior stops too.

Think about villager farms and wool machines before turning it off.

TNT is not included

TNT still explodes with mobGriefing off. On Bedrock, /gamerule tntexplodes false stops TNT. See the TNT guide.

Protect only one area

Game rules cannot target an area. To keep a base safe, stop hostile mobs spawning there with light (see stop mobs spawning). Servers usually use a protection plugin for areas.

When it does not work

Common questions

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.