Saudi Arabia has led a diplomatic drive in recent months to counterbalance what is regarded as Iran's growing influence in Iraq, Lebanon and the Palestinian Territories.
While Saudi Arabia is a key US ally in the Middle East, Iran is a fierce opponent of Western influence in the region.
The meeting lasted only a few hours before Ahmadinejad left Riyadh late on Saturday.
The United States and its regional allies, including Israel and Saudi Arabia, suspect Iran's nuclear energy programme aims to develop weapons, an accusation Tehran denies.
Saudi official, speaking before Saturday's meeting, said the kingdom would try to convince Tehran to comply with UN resolutions and suspend enrichment.
Iranian state radio said talks would also cover "Iran's nuclear case".
Saudi Arabia, Iran and Syria have accepted Iraq's invitation to a regional conference in March on easing tensions in Iraq.