The Battle of Cerneja took place at Cernesa, an unidentified site in Galicia, in 1139/40, between the County of Portugal and the Kingdom of León. In the aftermath of the Portuguese victory at the Battle of São Mamede, the Portuguese count, Afonso Henriques, began a concerted effort to establish his independence, growing increasingly uncomfortable sharing power with his mother, Countess Theresa, who was supported by the Galician nobility and her lover, Fernando Pérez de Traba. The Chronica Adefonsi imperatoris notes that "prior to this, the Portuguese monarch had come to Galicia several times, but always he had been driven back by Fernando Pérez and Rodrigo Vélaz and other Galician leaders. Often he was forced to return to Portugal dishonored." Between 1137, when he signed the Treaty of Tui, recognising Alfonso VII of León as his suzerain, and 1139 Afonso declared himself King of Portugal. In that year, or more probably the next, Afonso gathered an army and marched into Galicia, camping near Limia. Fernando Pérez, who controlled western Galicia, and his ally Rodrigo Vélaz, who controlled the east, summoned the other Galician nobles, described as loyal men of Alfonso VII, to oppose the Portuguese advance. In the subsequent battle they were routed. The anonymous author of the Chronica, who attributes their defeat to their sins, recounts the expedition in one paragraph:
Once more Alfonso, King of Portugal, gathered his army and went to Limia. When this news reached Galicia, Fernando Pérez and Rodrigo Vélaz and other of the Emperor's Galician nobles were summoned immediately. They marched out with their troops against the Portuguese King and met him at Cernesa. After the battle lines were drawn up, they began to fight. Because of their sins the Countsfled and were defeated. However, Rodrigo Vélaz was captured by some Portuguese knights. He was quickly freed by two of his armorbearers who used some clever stratagem, and thus he was able to flee with them.