The Goblin Army starts with a Goblin Battle Standard or at dawn after you break a Shadow Orb or Crimson Heart. Here is how to craft the standard, beat the invasion and free the Goblin Tinkerer.
You start the Goblin Army in Terraria by using a Goblin Battle Standard, crafted from 10 Tattered Cloth and 5 Wood at a Loom. It only works if someone in the world has at least 200 maximum health, and the item is used up.
The Goblin Army can also arrive by itself at dawn once you have broken a Shadow Orb or Crimson Heart. Beating it for the first time is the only way to unlock the Goblin Tinkerer, who reforges your gear and sells the Tinkerer's Workshop.

Tattered Cloth only drops from Goblin Scouts. They are rare enemies that walk around the surface in the outer sixth of the world, on both the far left and the far right.

Note: Every Goblin Scout drops 1 or 2 Tattered Cloth, so expect to hunt five to ten of them for one Battle Standard.
At 4:30 AM each day, the game checks whether a Goblin Army can begin. All of these have to be true:
Until you beat it for the first time, the chance is 1 in 3 every dawn. After that it drops to 1 in 30 before Hardmode and 1 in 60 in Hardmode.
The army comes from one edge of the world, with a message that says whether it comes from the west or the east, and walks toward your spawn point.
The event ends after you kill enough goblins: 120 in single player, plus 40 for every extra player with 200 health. A progress bar shows how far you are.
Fight on a raised platform or a wall of blocks at your spawn, so the melee goblins can't reach you. Flails, spears and piercing weapons hit several goblins at once, and the Spiky Balls they drop make a free trap, since most goblins walk right into them.
Note: Goblin Peons break doors instead of opening them. Open every door near your base before the army arrives, or your NPCs may move out of their broken houses.
Every goblin except the Warlock can drop Spiky Balls and, rarely, the Harpoon. In Hardmode, Goblin Warlocks have a chance to drop one of three Shadowflame items:

After your first win, the Goblin Tinkerer appears tied up somewhere in the Cavern layer as the Bound Goblin. Find him, talk to him to free him, and he moves into a free house.
He sells the Tinkerer's Workshop for combining accessories, the Rocket Boots and the Spiky Ball, and he can reforge any weapon or accessory for a better modifier. For one of the best accessories you build at his workshop, see How To Get The Ankh Shield.