The history of the word derby is intertwined with the history of the horse races that are held annually. In America, we tend to think of the Kentucky Derby at Churchill Downs when we hear the word derby, but the original derby is an annual horse race run at Epsom Downs near London, England. The first of these races took place in the year 1780 and got its name from the race's founder, Edward Stanley, the 12th Earl of Derby. (Stanley's title comes from the name of an English county and town.)
Another guest was Sir Charles Bunbury, described as “one of racing’s great administrators” by John Carter in his book The History of Horse Racing: First Past the Post. Carter further notes that “during the celebration after the first Oaks, the Earl, whose horse had been victorious in the race, was inspired by conversations with Sir Charles Bunbury, to introduce an additional race.” The new race would be for 3-year-old colts, and it was soon determined that one of the two men would lend his name to the race, with a coin flip determining the winner. Thus, on the whim of a coin, the new race became known as the Derby.
— J. Keeler Johnson, AmericasBestRacing.net, 22 Apr. 2020
Later, people started using the word derby for important horse races in other countries, and then for any race or contest open to all comers or to a specified category of contestants—for example, a fishing derby or a bicycle derby.
The sense of derby meaning "a stiff felt hat with a dome-shaped top and a narrow brim" is first recorded in the late 19th century. Apparently, this type of hat was first made in the 1860s by a London hatter named Bowler; thus, it is called a bowler hat in England and in the United States either derby or simply bowler. No one knows just how this hat came to be called a derby, but it probably started when men began to wear such hats on sporting occasions, as when going to the races.
Americans pronounce the first syllable of derby so that it rhymes with fur, but the British pronounce it so that it rhymes with far.