Nehemiah 9:17 (ESV) … “They refused to obey and were not mindful of the wonders that you performed among them, but they stiffened their neck and appointed a leader to return to their slavery in Egypt. But you are a God ready to forgive, gracious and merciful, slow to anger and abounding in steadfast love, and did not forsake them.”
After God had been so gracious, what had gone wrong? Why had God’s people divided into two small kingdoms, and why had those kingdoms fallen into the hands of the foreign powers Assyria (who captured and annexed the kingdom of Israel) and Babylon (who defeated Judah and destroyed Jerusalem and the temple in the process)? The answer according to Nehemiah 9:16–31 was simple: they had acted presumptuously and “stiffened their necks” or rebelled instead of obeying God humbly. The rebellion was made all the more inexcusable by God’s direct gift of God’s commandments—in plain Hebrew, so to speak! Indeed, even while they were yet in the wilderness they had longed to return to the relative security of slavery in Egypt. (Living by faith can be a dangerous-appearing adventure.)
Verse 17b quotes a confession of faith familiar to readers of the Bible from Exodus 16:2–3 and Numbers 14:11–12: “You are a merciful God ready to forgive, gracious and merciful, slow to anger and abounding in steadfast love” (NRSV). Verse 17b adds that God did not forsake them. J. H. Newman subjects this citation to scrutiny and argues as follows. The rhetorical effect of historical retrospects, this one in particular, was to show “how God had acted in the past as well as by divine promises made in the past. In the post-exilic period, the record of those acts and promises lay in texts and so the remembrance of history was shaped by the words in those texts.… Exodus 34:6–7 … came to be used as a focus and refrain … [in Neh 9:17] as a true representation of God’s gracious and compassionate character.” 
In contrast to the longsuffering of God, Israel was stiff-necked and rebellious throughout its history. Still, the Lord remained merciful (9:16–31). The prayer concluded with supplications. They admitted that God had justly chastened them by Gentile oppression, but now they prayed that God might see their economic distress and rescue them from oppression (9:32–37). Their prayer of confession concluded with the nation entering an oath of commitment to obey the law of Moses (9:38). 
The main lesson to be drawn here is that God is faithful to his promise made even when His people are not. Sometimes we see the faithfulness of God in his chastening hand.
 Redditt, P. L. (2014). Ezra-Nehemiah. (L. Andres & S. E. Balentine, Eds.) (p. 300). Macon, GA: Smyth & Helwys Publishing, Incorporated.  Dockery, D. S. (Ed.). (1992). Holman Bible Handbook (p. 297). Nashville, TN: Holman Bible Publishers.