Castillo called on his supporters to be vigilant and defend each vote from possible foul play.
“We must be vigilant to defend the democracy that is expressed in each of the votes, inside and outside our beloved Peru. We can't rest. May this historic vigil pave the way for the rebirth of a new country,” Castillo tweeted.
The National Office of Electoral Processes (ONPE) said that it had so far counted 96% of the vote.
Of those, Castillo was the preferred candidate for 50.29% of voters, while right-wing candidate Keiko Fujimori was the preferred option for 49.71%.
The president of ONPE Pedro Corvetto said that turnout was 77% in the election.