The Federation was founded in San Francisco, Earth in 2161. The seeds of the Federation were planted during the Babel Crisis of 2154, during which a temporary alliance was formed to search for a Romulan drone-ship preying on local vessels. It was this that first brought together the four species that would found the Federation: Humans, Vulcans, Andorians, and Tellarites. After the crisis, these four species remained together, founding the precursor to the Federation, called the Coalition of Planets, a year later. Other species soon joined: the Denobulans, the Rigelians, the Coridanites, and several others. Over the next several years, the ties between the members of the Coalition strengthened and became more structured, until, finally, in 2161, the Coalition became the Federation.
Although the Federation’s intentions were peaceful, around it were other, more belligerent powers such as the Klingon andRomulan Empires. As it expanded through the admittance of more and more worlds, it came into conflict with these powers. In the 23rd century, its main adversary was the Klingon Empire, with conflict erupting between the two twice in the 23rd century, before being halted by the Organians. However, tensions eased considerably towards the end of the century, with the Khitomer Conference of 2293 being a substantial turning point. This conference saw the signing of the Khitomer Accords, which effectively ended hostile relations.
At the start of the 24th century, the Federation began an unprecedented period of peaceful exploration of the galaxy, free of major conflicts, as its main adversary of the previous century, the Klingon Empire, was now at peace with it. However, relations with the Romulans remained hostile, albeit at a low, ‘cold war’ level. There was also a series of local conflicts in the late 2340s, as the Federation came into contact with other militant races such as the Cardassians, the Talarians, the Tholians and the Tzenkethi.
Then, however, the period of peaceful exploration came to an abrupt end. In 2365, the Federation encountered its single worst threat in the cybernetic pseudo-race known as the Borg. One of the most powerful and destructive forces in the entire galaxy, the Borg invaded the Federation. They were unlike anything the Federation had ever encountered, and were only foiled by chance and resourcefulness. The Federation was thus schooled in the fact that, in the vast, unexplored reaches of the galaxy beyond what they knew, there were threats that they could not even imagine.
Taken from Memory Alpha, with changes to reflect game setting.