presidential election, amid concerns that post-poll violence could undermine the fight against Boko Haram militants.
Boko Haram has killed thousands, kidnapped hundreds and displaced more than a million people during its campaign to carve out an Islamic state in the northeast of Nigeria, Africa's most populous nation.
Overnight Boko Haram attacked the main northeastern city of Maiduguri, leading to hours of fighting before Nigerian troops repelled the militants.
Kerry's visit to the commercial capital Lagos, in which he was to hold talks with incumbent President Goodluck Jonathan and challenger Muhammadu Buhari, highlights the stakes for Washington in what is expected to be Nigeria's closest election since its 1999 transition from military rule.
Kerry will "emphasize to both of the candidates the importance of non-violence in this election and having a free and fair and transparent process", said a senior State Department official, speaking on condition of anonymity.
He will argue "in particular that the loser accepts the results and discourages supporters from responding in any violent fashion," the official said.
Kerry's visit, which he announced only on Friday, marks an unusual intervention so close to a national election.
For example, the White House has said President Barack Obama will not meet Prime Minister Benjamin Netanyahu when the Israeli leader visits Washington in March in order not to be seen as choosing sides on the eve of an election in Israel.
U.S. officials say there is a difference between Obama meeting a sitting foreign leader at the White House and Kerry urging calm by meeting both candidates in Nigeria.