Holders Celtic will host Premiership newcomers Falkirk in the last 16 of the Premier Sports Cup.
Today's draw produced a repeat of last season’s quarter-final, which Brendan Rodgers’ side won 5-2 on their way to lifting the trophy.
Rangers were also handed a home tie as League One side Alloa Athletic, surprise winners of Group C, were rewarded with a trip to Ibrox.
Alloa are the only third-tier side left in the competition after a 3-2 win at Airdrie on Saturday maintained their 100-per-cent record in the group phase.
There are four all-Premiership ties, with Kilmarnock at home to Dundee United, Livingston hosting Hibs and St Mirren entertaining Hearts.
The knockout stage introduces the five clubs who qualified for Europe and were spared participation in the groups. All five were seeded alongside Hearts, St Johnstone and Partick Thistle, the three best section winners.
Killian Phillips celebrates the first of his two goals in St Mirren's victory against Ayr United
Ayr manager Scott Brown can look forward to a last-16 tie against Partick Thistle at Firhill
Falkirk boss John McGlynn watches his team beat Spartans to set up a last-16 tie against Celtic
The draw was held shortly after St Mirren rounded off the group phase with a 2-1 victory against Ayr United in Paisley. Despite that result, Ayr progressed as one of the three best group runners-up and can now look forward to an all-Championship tie against Partick, who eliminated Ross County by beating them 3-1 in Dingwall on Saturday.
The last 16 also paired St Johnstone with Motherwell and Morton with Aberdeen.
Ayr started the day top of Group D and would have gone through as a seeded team had they beaten St Mirren, but a poor first-half display proved costly for Scott Brown’s side as Killian Phillips scored twice for the home team to take his tally to four in two games.
The midfielder’s first goal came after 16 minutes, when goalkeeper David Mitchell failed to deal with his low shot and defender Nick McAllister could not prevent it crossing the line.
When Roland Idowu picked him out in the box, the Irishman cleverly guided his second home seven minutes before half-time.
Lifted by the introduction of Jude Bonnar, the midfielder on loan from Celtic, Ayr pulled one back through Kevin Holt. His header dipped under the bar after a corner by Dom Thomas.
Saints saw the game out to top the group on a day when Dunfermline were denied a place in the last 16 on goal difference. On a high-scoring weekend, St Johnstone thrashed 10-man Elgin City 8-0 and Livingston beat Kelty 6-0, while Dundee and Raith each scored five against Montrose and Inverness respectively.
Last 16 draw: Celtic v Falkirk, Kilmarnock v Dundee Utd, Rangers v Alloa, Livingston v Hibs, St Johnstone v Motherwell, Morton v Aberdeen, Partick v Ayr, St Mirren v Hearts (ties to be played August 16-17)