Witt, Melendez and Rivera each had two hits.
''The young guys provided a lot of excitement,'' Royals manager Mike Matheny said. ''It was fun to watch them.''
Rivera's sinking liner escaped a diving Adam Engel, rolling into the right field corner for a triple that drove in Melendez with the tiebreaking run in the sixth.
Melendez padded the lead with a two-run homer, his second, in the eighth.
''It felt really good,'' Melendez said. ''Going into that at-bat, I had a really good plan. I felt really confident. Anything to the outfield I felt pretty confident to get that run in.''
Witt hit his fourth home run, a 436-foot drive off White Sox starter Lucas Giolito.
''(He) hits the ball hard,'' Matheny said. ''That's what he's always done all the way through the minor league system. Even as an amateur, that's the thing that's always stood out. To have consistently hard contact. He's in a really good place now. He's got enough power when he's short to the ball.''
In his return from the COVID-19-related injured list, Giolito labored early, needing 54 pitches to complete the first two innings, allowing four hits and two walks.
''(It was) not my best,'' Giolito said. ''But I'm happy to be back, and back in a normal routine.''
After Witt's leadoff homer in the third, however, he struck out six of the next seven batters and permitted only a pair of singles before being lifted after five innings.
Royals starter Zack Greinke hasn't won since Aug. 13 last year, while with the Astros. He allowed two runs on seven hits, striking out four in 5 2/3 innings.
''We've got to get him a win, 'cause he's throwing good enough to have a bunch of them,'' Matheny said. ''He's a joy to watch. That's pitching at its finest, how he manipulates and makes minor adjustments, figuring out ways to get the break he wants on his slider. He's very unique and he's doing such a great job of making big pitches in big situations.''
''I think the last time I paid attention (to wins) was 2005,'' Greinke said. ''I started pitching good, but didn't get many wins and then started trying to do more and then started making mistakes, trying to get wins instead of trying to get outs. Nowadays, it's harder than ever. It's harder to go deep in games than it used to be.''
Greinke walked Engel in the fifth, his first free pass since April 21 against Minnesota, a span of 128 batters.
The second of Tim Anderson's three singles drove in Engel to make it 2-all. Anderson has nine multi-hit performances in his last 17 contests, batting .378 (28 for 74) in that span.
Rookie Collin Snyder (3-1) recorded the final out of the sixth for the win. Reynaldo Lopez (4-1) took the loss.
Royals OF Michael A. Taylor was removed from Wednesday's lineup due to MLB's COVID-19 protocols for contact tracing.
The White Sox reinstated Giolito and RHP Davis Martin was optioned to Triple-A Charlotte. RHP Lance Lynn was transferred to the 60-day IL.
The White Sox and Royals conclude their five-game series Thursday. RHP Vince Velasquez (2-3, 5.53 ERA) starts for the White Sox against RHP Carlos Hernandez (0-3, 9.11 ERA).
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Copyright 2022 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.