You'll use a QR battle code to challenge someone else with a team of three Pokémon. Though you'll usually need to be close to another player to battle them, you can play against your actual friends wherever they are as long as they're on your Ultra or Best Friends lists.
Niantic Labs is funneling players into three leagues, which have CP limits on Pokémon to make sure fights are somewhat fair -- you can only face off against others in the same division. Before you hop into a real-time battle, you'll have the option of using candy and stardust resources to give your Pokémon an extra charged attack, while you can use protect shields during a fight to defend them. Both you and your rival will receive rewards after the dust settles.
It's a long-awaited and much-needed addition to Pokémon Go that should galvanize many players and lure back in others who have drifted away. Niantic is continuing to add features to keep players interested, including trading and new Pokémon.