of 2023, second quarter of 2023 and the same quarter a year ago. The average yield on loans was 5.42% for the third quarter of 2023, compared to 5.28% for the second quarter of 2023 and 4.73% for the third quarter of 2022. The increase in the average yield on loans from the third quarter of 2023 and the third quarter of 2022 was due to the impact of increased rates on variable rate loans as well as new loans being originated at higher market interest rates.
Interest income on loans included $372,000, $5,000, and $63,000 in accretion of the net discount on acquired loans for the three months ended September 30, 2023, June 30, 2023, and September 30, 2022, respectively. The balance of the net discounts on these acquired loans totaled $419,000, $331,000, and $480,000 at September 30, 2023, June 30, 2023, and September 30, 2022, respectively. Interest income included minimal fees earned related to Paycheck Protection Program (“PPP”) loans in the quarters ended September 30, 2023 and June 30, 2023, and $161,000 during the quarter ended September 30, 2022. Interest income also included fees related to prepayment penalties of $142,000 in the quarter ended September 30, 2023, compared to $48,000 in the second quarter of 2023, and $195,000 in the third quarter of 2022.
Interest income on investment securities increased $11,000, or 0.6%, from the prior quarter and totaled $1.7 million for both the three months ended September 30, 2023 and the three months ended June 30, 2023, and increased $149,000, or 9.6%, from $1.6 million for the three months ended September 30, 2022. Average yield on investment securities increased two basis points to 4.01% for the three months ended September 30, 2023, compared to 3.99% for the three months ended June 30, 2023, and increased 74 basis points from 3.27% for the three months ended September 30, 2022. The average balance of investment securities totaled $168.6 million for the three months ended September 30, 2023, compared to $170.1 million and $188.7 million for the three months ended June 30, 2023 and September 30, 2022, respectively. In addition, during the third quarter of 2023, we received $376,000 in cash dividends on our FRB and FHLB stock, up 10.6% from $340,000 in the second quarter of 2023 and up 31.9% from $285,000 in the third quarter of 2022.
Interest income on federal funds sold and interest-bearing balances in banks increased $961,000, or 37.5%, to $3.5 million for the three months ended September 30, 2023, compared to $2.6 million for the three months ended June 30, 2023, and increased $2.2 million, or 173.8%, from $1.3 million for the three months ended September 30, 2022 as a result of an increase in the average yield. The average yield on federal funds sold and interest-bearing balances in banks increased 24 basis points to 5.38% for the three months ended September 30, 2023, compared to 5.14% for the three months ended June 30, 2023, and increased 320 basis points from 2.18% for the three months ended September 30, 2022. The average balance of federal funds sold and interest-bearing balance in banks totaled $259.6 million for the three months ended September 30, 2023, compared to $199.9 million and $234.6 million for the three months ended June 30, 2023 and September 30, 2022, respectively.
Interest expense increased $1.0 million, or 14.9%, to $8.0 million for the three months ended September 30, 2023, compared to $7.0 million for the three months ended June 30, 2023, and increased $5.6 million, or 232.5%, compared to $2.4 million for the three months ended September 30, 2022, reflecting higher funding costs primarily related to increased market rates of interest on our deposits. Average balance of deposits totaled $2.2 billion for the third quarter of 2023 compared to $2.1 billion for the second quarter of 2023, and $2.2 billion for the third quarter of 2022. The average cost of funds for the third quarter of 2023 was 2.04%, compared to 1.82% for the second quarter of 2023 and 0.66% for the third quarter of 2022. The increase in the average cost of funds during the current quarter compared to the prior quarter of 2023 and the third quarter of 2022 was due to higher interest rates paid on money market and time deposits due to increased competition and pricing pressures and a change in deposit mix due to shift of deposits from noninterest bearing accounts to higher costing money market and time deposits. The average cost of total deposits for the three months ended September 30, 2023 was 1.27%, compared to 1.10% for the three months ended June 30, 2023, and 0.25% for the three months ended September 30, 2022. The average balance of noninterest bearing deposits decreased $2.7 million, or 0.4%, to $674.8 million for the three months ended September 30, 2023, compared to $677.5 million for the three months ended June 30, 2023 and decreased $127.1 million, or 15.8%, compared to $801.9 million for the three months ended September 30, 2022. Interest expense on junior subordinated debt increased $14,000, or 6.9% to $217,000 for the three months ended September 30, 2023 compared to $203,000 for the three months ended June 30, 2023, and increased $88,000, or 68.2%, compared to $129,000 for the three months ended September 30, 2022, due to higher market rates.
Annualized net interest margin was 4.03% for the third quarter of 2023, compared to 4.02% for the second quarter of 2023 and 3.99% for third quarter of 2022. The average yield on interest earning assets for the third quarter of 2023 increased 16 basis points and 96 basis points over the average yields for the second quarter of 2023 and the third quarter of 2022,