Iraqis are due to form a new government after an election in April in which Maliki's list won the most seats in parliament but would still require allies to win a majority.
U.S. officials have conveyed that they are open to Maliki leaving. Senior Iraqi politicians, including at least one member of Maliki's own ruling list, have told Reuters that this message has been delivered in diplomatic language to Iraqi leaders.
Recent meetings between Maliki and the Americans have been described as tense. According to a Western diplomat briefed on the conversations by someone attending the meetings, U.S. diplomats have informed Maliki he should accept leaving if he cannot gather a majority in parliament for a third term. U.S. officials have contested that such a message was delivered.
A close ally of Maliki has described him as having grown bitter toward the Americans in recent days over their failure to provide strong military support in the face of the militant advance.
Read MoreKerry in Cairo for talks over Iraq
On Sunday, militants overran a second frontier post on the Syrian border, extending two weeks of swift territorial gains as ISIL pursues the goal of a caliphate straddling both countries that has raised alarm across the Middle East and in the West.
The need to battle the Sunni insurgency has put the United States on the same side as its enemy of 35 years, Iran, which has close ties to the Shi'ite parties that came to power in Baghdad after U.S. forces toppled Saddam. However, Khamenei's comments made clear that a rapprochement would not be easy.
"We are strongly opposed to U.S. and other intervention in Iraq," IRNA news agency quoted Khamenei as saying. "We don't approve of it as we believe the Iraqi government, nation and religious authorities are capable of ending the sedition."
Some Iraqi observers in Baghdad interpreted Khamenei's comments as a warning to the United States to stay out of the process of selecting any successor to Maliki.
Baghdad is Kerry's third stop in a tour of Middle East capitals to emphasize the threat the insurgency poses to the region and call on Iraq's allies to use their influence to press Baghdad to govern more inclusively. He has also been warning Iraq's neighbours they need to step up efforts to cut off cross-border funding to the militants.