Although the Federation’s intentions were peaceful, around it were other, more belligerent powers such as the Klingon and Romulan 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 war briefly erupting between the two in 2267, before being halted by the Organians. (TOS: “Errand of Mercy”) However, tensions eased considerably towards the end of the century, with the Khitomer Conference of 2293 being a substantial turning point. (Star Trek VI: The Undiscovered Country) This conference saw the signing of to 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.
Starfleet forces engaging the Borg.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 twice invaded the Federation. They were unlike anything the Federation had ever encountered, and were only foiled by chance and Human 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. (TNG: “Q Who”, “The Best of Both Worlds”, “The Best of Both Worlds, Part II”; Star Trek: First Contact)
The Breen hit the heart of Starfleet.Then, in 2370, contact was made with the Dominion, the predominant ruling power over much of the Gamma Quadrant. After numerous skirmishes, misfortunes suffered by the Cardassian Union allowed for their eventual incorporation into the Dominion, and the subsequent Dominion invasion of the Alpha Quadrant. The Dominion/Cardassian forces were also joined by the reclusive but immensely powerful race known as the Breen. The ensuing war was the greatest crisis to be faced by the Federation, with the Federation forming an alliance with the Klingons and Romulans to defeat the Dominion. Although the Alliance eventually emerged victorious, many of the Federation’s important member worlds, such as Betazed, Coridan, and Benzar, had been temporarily occupied before the Dominion’s offensive could be turned back. Thousands of Federation Starfleet vessels and millions of lives were lost, in what turned out be, as of the late 24th century, the bloodiest conflict in Federation history. (DS9: “By Inferno’s Light”, et al.) The most devastating and demoralizing offensive occurred in 2375, when the Breen hit the Federation at its heart, with a surprise attack on Starfleet Headquarters on Earth. (DS9: “The Changing Face of Evil”)
However, the war and its aftermath allowed the Federation to establish new relations with many of its former adversaries, the Romulans in particular. In 2379, cooperation took place between the crew of a Federation Starfleet vessel, the USS Enterprise-E, and Romulan forces to defeat the Romulan Praetor Shinzon, whose actions would have destroyed both Earth and the Romulan Star Empire. It was hoped that this would mark the beginning of and end to hostility between the Federation and the Romulan Star Empire, marking the beginnings of détente with a traditional enemy of the Federation. (Star Trek Nemesis)