Ecgfrith was born in 645 to king Oswiu and Eanflæd his queen. At about the age of 10 Ecgfrith was held as a hostage at the court of Queen Cynewise after her husband king Penda of Mercia invaded Northumbria in 655. Penda was eventually defeated and killed in the Battle of the Winwaed by Oswiu a victory which greatly enhanced Northumbrian power. To secure his hegemony over other English kingdoms Oswiu arranged a marriage between Ecgfrith and Æthelthryth, a daughter of Anna of East Anglia, he was possibly as young as 15 at the time. Ecgfrith was then made king of Deira in 664 after his half-brother Alhfrith had rebelled against Oswiu earlier that year.
In 671, at the Battle of Two Rivers, Ecgfrith put down an opportunistic rebellion by the Picts, which resulted in the Northumbrians taking control of the land between the Firth of Forth and the Tweed for the next fourteen years. Around the same time, Æthelthryth wished to leave Ecgfrith to become a nun. Eventually, in about 672, Æthelthryth persuaded Ecgfrith to allow her to become a nun, and she entered the monastery of the Abbess Æbbe, who was aunt to King Ecgfrith, at Coldingham. A year later Æthelthryth became founding abbess of Ely.
In 674, Ecgfrith repelled the Mercian king Wulfhere, which enabled him to seize Lindsey. In 679, he fought the Mercians again, now under Wulfhere's brother Æthelred who was married to Ecgfrith's sister Osthryth, at the Battle of the Trent. Ecgfrith's own brother Ælfwine was killed in the battle and following intervention by Theodore, the Archbishop of Canterbury, Lindsey was returned to the Mercians.
In June 684, Ecgfrith sent a raiding party to Brega in Ireland under his general Berht, which resulted in the seizing of a large number of slaves and the sacking of many churches and monasteries. The reasons for this raid are unclear, though it is known that Ecgfrith acted against the warnings of Ecgberht of Ripon and that the raid was condemned by Bede and other churchmen.
In 685, against the advice of Cuthbert of Lindisfarne, Ecgfrith led a force against the Picts of Fortriu, who were led by his cousin Bridei mac Bili. On 20 May, Ecgfrith along with most of his men was slain at the age of 40. He was lured by a feigned flight in the mountains and slain at what is now called the Battle of Nechtansmere, located at either Dunnichen in Angus or Dunachton in Badenoch. This defeat severely weakened Northumbrian power in the north and Bede dates the beginning of the decline of the kingdom of Northumbria from Ecgfrith's death and wrote that following Ecgfrith's death, "the hopes and strengths of the English realm began 'to waver and to slip backward ever lower". The Northumbrians never regained the dominance of central Britain lost in 679; nor of northern Britain lost in 685. Nevertheless, Northumbria remained one of the most powerful states of Britain and Ireland well into the Viking Age. Ecgfrith was buried on Iona and succeeded by his illegitimate half-brother, Aldfrith.