Updated:

Two teams in six lines

/team add red "Red team"
/team add blue "Blue team"
/team modify red color red
/team modify blue color blue
/team join red Steve
/team join blue Alex

Lines 1–2 create the teams, lines 3–4 set the name colors and lines 5–6 add players. red and blue are team IDs; the quoted text is the display name. You can use selectors such as @p or @a[tag=…] instead of player names.

Useful team options

GoalCommand
Name color/team modify red color red
Teammates cannot hurt each other/team modify red friendlyFire false
See invisible teammates/team modify red seeFriendlyInvisibles true
Hide name tags/team modify red nametagVisibility never
Players do not push each other/team modify red collisionRule never
Text before names/team modify red prefix "[Red] "

Colors: black, dark_blue, dark_green, dark_aqua, dark_red, dark_purple, gold, gray, dark_gray, blue, green, aqua, red, light_purple, yellow, white and reset. Test friendlyFire false before an event, because some damage such as explosions can behave differently between versions.

Selecting teams

SelectorTargets
@a[team=red]Everyone on red
@a[team=!red]Everyone not on red (including players with no team)
@a[team=]Players with no team
@a[team=!]Players on any team

For example, /tp @a[team=red] 100 64 100 sends the red team to its base.

Random teams

/team join red @r[team=]
/team join blue @r[team=]

@r[team=] picks one random player who has no team yet. Repeat the two lines in turn until everyone has a team.

Team chat and death messages

/teammsg Meet at the north gate
/team modify red deathMessageVisibility hideForOtherTeams

/teammsg (short form /tm) sends a message only to your own team. The second line hides red players' death messages from the other teams, which keeps hide-and-seek or PvP maps fair. Other values are always, never and hideForOwnTeam.

A sidebar only one team can see

/scoreboard objectives add redPoints dummy "Red points"
/scoreboard objectives setdisplay sidebar.team.red redPoints

sidebar.team.red shows the objective only to players on teams whose color is red, so each team can have its own score panel. The color in the slot name is the team color you set with /team modify … color, not the team ID.

Check and clean up

Common problems

Check your command

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