Aggro refers to gaining, controlling and losing the aggression of hostile NPCs, as well as the aggression of NPCs and any related mechanics in general. The aggro system is simple—NPCs will select targets primarily based on a range calculation, meaning the character or allied NPC such as minion or pet closest to the hostile NPC will hold its attention. However, there are additional factors such as which characters are doing damage, and how much each character has done. In addition, not all creatures (in particular, legendary creatures) use the same A.I. for aggro; some creatures will have unique aggro mechanics 
To gain the aggro of a hostile (red outlined) NPC, the player moves into the attack range of the creature. Depending on the damage and type of attack, whenever a player attacks an enemy, that player generates an amount of threat. The AI maintains an internal table that accounts for each player that attacked an enemy and a value representing the amount of threat.
Every hostile NPC maintains an aggro table. Internally, aggro tables function on a simple priority-queue principle: the head of the queue is occupied by the player that has the most threat and the tail of the queue is occupied by the player that has accumulated the least threat. The amount of threat does not simply mean damage since there are NPCs who are attracted to a certain attribute, if a player has a high amount of toughness/vitality and wears a shield, they could hit the mob just once and have unrivaled aggro from the mob. There are also instances whereby just being in the vicinity of the mob with a high enough attribute that the NPC is attracted to, would gain aggro without participation (damaging the mob/healing a player attacking the mob). Supposing that the top player has died, disconnected, or shaken off enough aggro to no longer be at the top, the AI chooses the next player or allied NPC on the queue that has generated the most threat, and attacks them.
Gaining and losing aggro
For a neutral (yellow outlined) NPC the player must attack first to gain its attention, turning it hostile. The aggro table of a hostile NPC changes dynamically depending on a number of factors.
There are multiple ways to gain the aggro of a hostile enemy. The following list is in no particular order.
- Who is the closest or furthest target
- Who is dealing or has recently dealt the most damage (or who has done the most number of attacks) in a certain amount of time
- Scripted decisions (ex., some enemies such as Giganticus Lupicus will pick a specific player and always teleport to him for the duration of the fight, unless they die)
- Who has the lowest level (Note: Mastery level is not counted)
- Who has the most toughness 
- Who is currently fixated
- Taunt (Does not work against enemies with a defiance bar)
Some players have suggested the following factors might influence certain enemies, but this is not confirmed by any official source (and seems to be based on assumptions from other MMOs that go against the principles stated by Guild Wars 2 developers):
- Who is using a shield or higher overall armor
- Who is reviving a fallen ally [verification requested]
Players who have gained unwanted aggro can lose it in several ways. The order of most quickest to slowest is the following:
- Cease dealing damage so that another player may draw aggro
- Moving far away or to a place enemies cannot reach (e.g. up a cliff enemies cannot get to)
Enemies who have lost aggro to all players will go out of combat and quickly heal back to full health. This may be interrupted by getting in combat with that enemy again.
Tanking in Guild Wars 2 does not require your character to be a specific class like in most other MMOs. All classes can be a tank, and arguably, some are better than others. Regardless, their job remains the same: keeping the aggro of the enemy on them at all times. The reason players would want to tank a boss is to either keep the enemy in one place at all times, move them to a more strategic area, or direct where their attacks will go.
Keeping aggro of the enemy is pretty difficult, but certain enemies (usually bosses) have mechanics that makes this job simpler.
- Having the highest toughness - Some bosses will keep their focus on the target with the highest toughness value. If another player gains more toughness during the fight, or their main target loses enough toughness (or dies), they will switch to the new target.
- Fixation - Some enemies will give a random player the Fixated effect. During this time, they will follow this player and all attacks will be in their direction. If the fixated player goes downed or dies, it will immediatly switch to the next available target. Fixation can also change based on certain mechanics. (e.g. after 30 seconds)
- Furthest target - Some enemies will choose the furthest player in the area and have some of their attacks go in their direction.
- Random person - Some enemies will choose a random person in the area when the fight begins and have some of their attacks focused in their direction. Another player will be chosen if their initial target has died.