The Captain has the final decision and a number of alternate airports are provided in the flight plan. These are usually given in order of company preference. In the event of major disruption, ATC may assign division airports to aircraft as it may not be possible for a nearby airport to cope with the sudden arrival of a large number of aircraft, this often happens in China.
In the event of a technical problem, the airline may ask the pilot to divert to a suitable airport where maintenance facilities are available rather than continue to destination.
The pilot in command always has final authority and may declare an emergency if the situation requires it. Once on the ground he must then justify his decision to various parties, including his company, national civil aviation authority and the authorities of the country he is in at the time. Legitimate reasons and good judgment are expected and will be supported.